-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_printf.c
More file actions
58 lines (53 loc) · 1.73 KB
/
ft_printf.c
File metadata and controls
58 lines (53 loc) · 1.73 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
56
57
58
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_printf.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: kfouad < kfouad@student.1337.ma> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/28 11:48:45 by kfouad #+# #+# */
/* Updated: 2022/11/12 17:31:19 by kfouad ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
int check_printf(char s, va_list arg)
{
int count;
count = 0;
if (s == 'c')
count += ft_putchar(va_arg(arg, int));
else if (s == 's')
count += ft_putstr(va_arg(arg, char *));
else if (s == 'p')
count += ft_putptr(va_arg(arg, unsigned long));
else if (s == 'd' || s == 'i')
count += ft_putnbr(va_arg(arg, long));
else if (s == 'u')
count += ft_putnbr_u(va_arg(arg, unsigned int));
else if (s == 'x')
count += ft_put_hex(va_arg(arg, unsigned int));
else if (s == 'X')
count += ft_put_hex_maj(va_arg(arg, int));
else
count += ft_putchar(s);
return (count);
}
int ft_printf(const char *s, ...)
{
va_list arg;
int i;
int count;
va_start(arg, s);
i = 0;
count = 0;
while (s[i])
{
if (s[i] != '%')
count += ft_putchar(s[i]);
else
count += check_printf(s[++i], arg);
i++;
}
va_end(arg);
return (count);
}