-
Notifications
You must be signed in to change notification settings - Fork 0
/
my_printf.c
50 lines (46 loc) · 1010 Bytes
/
my_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
/*
** EPITECH PROJECT, 2022
** my_printf
** File description:
** noe samy
*/
#include <unistd.h>
#include <stdarg.h>
#include "my.h"
static fonction_t funcs[] = {
{'c', my_putchar_ap},
{'d', my_putnbr_minus_ap},
{'i', my_putnbr_minus_ap},
{'s', my_putstr_ap},
{'%', my_putchar_percent_ap},
{'u', my_putnbr_ap},
{'o', my_putnbr_base_octal_ap},
{'x', my_putnbr_base_hexa_ap},
{'X', my_putnbr_base_hexa_maj_ap},
};
int print(char const *format, va_list *ap, int i)
{
for (int j = 0; j < 9; j++) {
if (funcs[j].c == format[i + 1]) {
return funcs[j].ptr(ap);
}
}
return 0;
}
int my_printf(const char *format, ...)
{
va_list ap = {0};
va_start(ap, format);
int taille = 0;
int i = 0;
for (; format[i] != '\0'; i++) {
if (format[i] == '%') {
taille += print(format, &ap, i);
i = i + 1;
} else {
taille += my_putchar(format[i]);
}
}
va_end(ap);
return taille;
}