-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_printf.c
More file actions
55 lines (51 loc) · 1.87 KB
/
Copy pathft_printf.c
File metadata and controls
55 lines (51 loc) · 1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_printf.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: yamzil <yamzil@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/12/10 15:57:55 by yamzil #+# #+# */
/* Updated: 2021/12/15 18:56:17 by yamzil ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
static int ft_check(char a, va_list arg_list)
{
if (a == 'c')
return (ft_putchar(va_arg(arg_list, int)));
else if (a == 's')
return (ft_putstr(va_arg(arg_list, char *)));
else if (a == 'd' || a == 'i')
return (ft_putnbr(va_arg(arg_list, int)));
else if (a == 'u')
return (ft_putun(va_arg(arg_list, unsigned int)));
else if (a == 'x')
return (ft_puthexalow(va_arg(arg_list, unsigned int)));
else if (a == 'X')
return (ft_puthexaupper(va_arg(arg_list, unsigned int)));
else if (a == 'p')
return (ft_putstr("0x") + ft_putcent(va_arg(arg_list, unsigned long)));
else if (a == '%')
return (ft_putchar('%'));
return (ft_putchar(a));
}
int ft_printf(const char *format, ...)
{
va_list arg_list;
int i;
int count;
i = 0;
count = 0;
va_start (arg_list, format);
while (format[i])
{
if (format[i] != '%')
count += ft_putchar (format[i]);
else if (format[i] == '%')
count += ft_check (format[++i], arg_list);
i++;
}
va_end (arg_list);
return (count);
}