-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_printf.c
68 lines (63 loc) · 1.9 KB
/
ft_printf.c
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_printf.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ahouari <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/11/20 16:29:19 by ahouari #+# #+# */
/* Updated: 2021/12/01 14:04:14 by ahouari ### ########.fr */
/* */
/* ************************************************************************** */
#include"ft_printf.h"
#include<stdio.h>
static void ft_write_value(char format, const void *arg, int *len )
{
if (format == 'c')
*len += ft_putchar((char)arg);
else if (format == 's')
*len += ft_putstr((char *)arg);
else if (format == 'i')
*len += ft_putnbr((int)arg);
else if (format == 'd')
*len += ft_putnbr((long)arg);
else if (format == 'u')
*len += ft_putnbr_u((unsigned int)arg);
else if (format == 'x')
ft_print_hexa_lower((unsigned int)arg, len);
else if (format == 'X')
ft_print_hexa_upper((unsigned int)arg, len);
else if (format == 'p')
ft_print_p((unsigned long)arg, len);
else if (format == '%')
*len += ft_putchar('%');
}
int ft_printf(const char *str, ...)
{
int len;
int i;
va_list lst;
void *next;
i = 0;
len = 0;
va_start(lst, str);
while (str[i])
{
if (str[i] == '%')
{
i++;
if (str[i] != '%')
next = va_arg(lst, void *);
ft_write_value(str[i], next, &len);
}
else
len += ft_putchar(str[i]);
i++;
}
va_end(lst);
return (len);
}
int main ()
{
ft_printf("%x",-1);
}