-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_printf.c
More file actions
64 lines (59 loc) · 1.93 KB
/
Copy pathft_printf.c
File metadata and controls
64 lines (59 loc) · 1.93 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_printf.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: pgomez-a <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/03/11 08:43:56 by pgomez-a #+# #+# */
/* Updated: 2021/04/09 17:06:12 by pgomez-a ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
static int pf_pct(va_list *ap, int ct, const char *format, int **result)
{
char *width;
ct++;
ct = pf_man_fmt(ap, ct, format, &width);
if (format[ct] == 'c')
pf_find_char(ap, &width, result);
else if (format[ct] == '%')
pf_find_pct(&width, result);
else if (format[ct] == 's')
pf_find_str(ap, &width, result);
else if (format[ct] == 'd' || format[ct] == 'i')
pf_find_int(ap, &width, result);
else if (format[ct] == 'u')
pf_find_uns(ap, &width, result);
else if (format[ct] == 'x' || format[ct] == 'X')
pf_find_hex(ap, format[ct], &width, result);
else if (format[ct] == 'p')
find_ptr(ap, &width, result);
free(width);
return (ct + 1);
}
int ft_printf(const char *format, ...)
{
va_list ap;
int *result;
int ct;
va_start(ap, format);
result = (int *)malloc(sizeof(int) * 1);
(*result) = 0;
ct = 0;
while (format[ct])
{
if (format[ct] == '%')
ct = pf_pct(&ap, ct, format, &result);
else
{
ft_putchar_fd(format[ct], 1);
(*result) += 1;
ct++;
}
}
ct = *result;
free(result);
va_end(ap);
return (ct);
}