-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_printf.c
More file actions
58 lines (54 loc) · 1.66 KB
/
ft_printf.c
File metadata and controls
58 lines (54 loc) · 1.66 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: tdehne <tdehne@student.42heilbronn.de> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/04/12 16:31:10 by tdehne #+# #+# */
/* Updated: 2022/04/30 14:38:43 by tdehne ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
static int ft_process_arg(char c, va_list arg)
{
if (c == 's')
return (write_s(arg));
if (c == 'i' || c == 'd' || c == 'c')
return (write_c_i(arg, c));
if (c == 'u')
return (write_u(arg));
if (c == 'p')
return (write_p(arg, "0123456789abcdef"));
if (c == 'x')
return (write_x_uppx(arg, "0123456789abcdef"));
if (c == 'X')
return (write_x_uppx(arg, "0123456789ABCDEF"));
if (c == '%')
return (write(1, "%", 1));
return (0);
}
int ft_printf(const char *str, ...)
{
va_list argptr;
int counter;
va_start(argptr, str);
counter = 0;
while (*str)
{
if (*str == '%')
{
str++;
counter--;
if (!*str)
break ;
counter += ft_process_arg(*str, argptr);
}
else
write(1, str, 1);
str++;
counter++;
}
va_end(argptr);
return (counter);
}