-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_printf.c
More file actions
51 lines (45 loc) · 772 Bytes
/
_printf.c
File metadata and controls
51 lines (45 loc) · 772 Bytes
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
#include "main.h"
#include <stdarg.h>
int _printf(const char *format, ...)
{
va_list args;
int count = 0;
int i = 0;
if (format == NULL)
return (-1);
va_start(args, format);
while (format[i] != '\0')
{
if (format[i] == '%')
{
if (format[i + 1] == '\0')
{
va_end(args);
return (-1);
}
i++;
if (format[i] == 'c')
count += print_char(args);
else if (format[i] == 's')
count += print_string(args);
else if (format[i] == '%')
count += print_percent(args);
else if (format[i] == 'd' || format[i] == 'i')
count += print_integer(args);
else
{
_putchar('%');
_putchar(format[i]);
count += 2;
}
}
else
{
_putchar(format[i]);
count++;
}
i++;
}
va_end(args);
return (count);
}