-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprintf.c
56 lines (55 loc) · 806 Bytes
/
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
#include "main.h"
/**
* _printf - print any and all things
* @format: first argument
* Return: bytes
*/
int _printf(const char *format, ...)
{
unsigned int i = 0, count = 0, slen = 0;
char *str;
va_list pr;
va_start(pr, format);
if (format == NULL)
{
return (-1);
}
while (format[i] != '\0')
{
if (format[i] != '%')
{
pr_char(format[i]);
count++;
}
else
{
switch (format[i + 1])
{
case 'c':
pr_char(va_arg(pr, int));
count++;
break;
case 's':
str = va_arg(pr, char *);
if (str != NULL)
{
slen = pr_str(str);
count += slen;
}
else
{
count += pr_str("(null)");
}
break;
case '%':
pr_char('%');
count++;
break;
}
i++;
}
i++;
}
va_end(pr);
return (count);
}