Repository navigation
Expand file tree
/
Copy pathft_printf.c
More file actions
74 lines (69 loc) · 2.14 KB
/
Copy pathft_printf.c
File metadata and controls
74 lines (69 loc) · 2.14 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
67
68
69
70
71
72
73
74
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_printf.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: damorim- <damorim-@student.42berlin.de> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/08/05 06:25:08 by damorim- #+# #+# */
/* Updated: 2026/08/13 15:14:00 by damorim- ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdarg.h>
#include <stdio.h>
#include "ft_printf.h"
#include "libft/libft.h"
int check_format(const char *format, int i, va_list args)
{
int counter;
counter = 0;
if (format[i + 1] == 'c')
counter = ft_printchar(va_arg(args, int));
else if (format[i + 1] == 's')
counter = ft_printstr(va_arg(args, char *));
else if (format[i + 1] == 'p')
counter = ft_printptr(va_arg(args, void *));
else if (format[i + 1] == 'i' || format[i + 1] == 'd')
counter = ft_putnbr(va_arg(args, int));
else if (format[i + 1] == 'u')
counter = ft_printunsignednum(va_arg(args, unsigned int));
else if (format[i + 1] == 'x')
counter = ft_printhex(va_arg(args, unsigned int));
else if (format[i + 1] == 'X')
counter = ft_print_caphex(va_arg(args, unsigned int));
else if (format[i + 1] == '%')
counter = print_percent();
else
{
print_percent();
counter = ft_printchar(va_arg(args, int));
}
return (counter);
}
int ft_printf(const char *format, ...)
{
int i;
int count;
va_list args;
if (format == NULL)
return (-1);
va_start(args, format);
i = 0;
count = 0;
while (format[i])
{
if (format[i] == '%')
{
count += check_format(format, i, args);
i++;
}
else
{
write(1, &format[i], 1);
count++;
}
i++;
}
va_end(args);
return (count);
}