-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_printf.c
More file actions
71 lines (66 loc) · 1.76 KB
/
ft_printf.c
File metadata and controls
71 lines (66 loc) · 1.76 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_printf.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jdecorte <jdecorte@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/10/19 15:27:35 by jdecorte #+# #+# */
/* Updated: 2021/10/19 17:00:03 by jdecorte ### ########.fr */
/* */
/* ************************************************************************** */
#include "includes/ft_printf.h"
t_print *ft_initialise_tab(t_print *tab)
{
tab->len = 0;
return (tab);
}
void ft_conv(char c, t_print *tab)
{
if (c == 'c')
ischar(tab);
else if (c == 's')
isstring(tab);
else if (c == 'p')
ispointer(tab);
else if (c == 'd' || c == 'i')
isint(tab);
else if (c == 'u')
isdecint(tab);
else if (c == 'X')
ishexmaj(tab);
else if (c == 'x')
ishexmin(tab);
else if (c == '%')
isperc(tab);
}
int ft_printf(const char *input, ...)
{
t_print *tab;
int i;
int len;
tab = malloc(sizeof(t_print));
if (!tab)
return (-1);
tab = ft_initialise_tab(tab);
i = 0;
va_start(tab->args, input);
while (input[i])
{
if (input[i] == '%')
{
if (ft_strchr("cspdiuxX%", input[i + 1]))
ft_conv(input[i++ + 1], tab);
}
else
{
ft_putchar(input[i]);
tab->len++;
}
i++;
}
va_end(tab->args);
len = tab->len;
free(tab);
return (len);
}