-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_printf.c
More file actions
66 lines (61 loc) · 1.8 KB
/
Copy pathft_printf.c
File metadata and controls
66 lines (61 loc) · 1.8 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
59
60
61
62
63
64
65
66
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_printf.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: moben-ta <moben-ta@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/12/02 13:20:49 by moben-ta #+# #+# */
/* Updated: 2024/12/05 16:09:48 by moben-ta ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
int check_format(char c, va_list arg)
{
int count;
count = 0;
if (c == 'd' || c == 'i')
count = ft_putnbr(va_arg(arg, int));
else if (c == 'c')
count = ft_putchar(va_arg(arg, int));
else if (c == 's')
count = ft_putstr(va_arg(arg, char *));
else if (c == 'u')
count = ft_putunbr(va_arg(arg, unsigned int));
else if (c == 'x' || c == 'X')
count = ft_puthex(va_arg(arg, unsigned int), c);
else if (c == 'p')
count = ft_putp(va_arg(arg, void *));
else if (c == '%')
count = ft_putchar(c);
else
count += ft_putchar(c);
return (count);
}
int ft_printf(const char *format, ...)
{
va_list arg;
int count;
int i;
va_start(arg, format);
count = 0;
i = 0;
while (format[i])
{
if (format[i] == '%')
{
i++;
if (format[i] == '\0')
return (count);
count += check_format(format[i], arg);
}
else
{
ft_putchar(format[i]);
count++;
}
i++;
}
va_end(arg);
return (count);
}