-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_printf.c
More file actions
69 lines (64 loc) · 1.79 KB
/
ft_printf.c
File metadata and controls
69 lines (64 loc) · 1.79 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_printf.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: havyilma <havyilma@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/26 18:25:23 by havyilma #+# #+# */
/* Updated: 2022/11/09 16:49:39 by havyilma ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
int ft_formatter(char t, va_list arg)
{
int i;
i = 0;
if (t == 'c')
i += ft_putchar (va_arg (arg, int));
if (t == 's')
i += ft_putstr (va_arg (arg, char *));
if (t == 'p')
{
i += ft_putstr ("0x");
i += ft_printlower (va_arg(arg, unsigned long));
}
if (t == 'd' || t == 'i')
i += ft_putnbr(va_arg(arg, int));
if (t == 'u')
i += ft_printdecimal(va_arg(arg, unsigned int));
if (t == 'x')
i += ft_printlower (va_arg(arg, unsigned int));
if (t == 'X')
i += ft_printupper (va_arg(arg, unsigned int));
if (t == '%')
i += ft_putchar ('%');
return (i);
}
int ft_printf(const char *str, ...)
{
va_list lst;
int i;
int j;
j = 0;
i = 0;
va_start(lst, str);
while (str[i])
{
if (str[i] == '%')
{
i++;
while (str[i] == ' ' && str[i])
{
i++;
j++;
}
j += ft_formatter(str[i], lst);
}
else
j += ft_putchar(str[i]);
i++;
}
va_end(lst);
return (j);
}