-
Notifications
You must be signed in to change notification settings - Fork 0
/
0.c
47 lines (41 loc) · 678 Bytes
/
0.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
#include "main.h"
#include <stdarg.h>
/**
* _printf - prints the *format
* @format: character string
*
* Return: number of printed char
*/
int _printf(const char *format, ...)
{
va_list args;
int count = 0;
va_start(args, format);
if (format == NULL)
return (-1);
while (*format)
{
if (*format == '%')
{
format++;
if (*format == '%')
{ putchar('%');
count++; }
else if (*format == 'c')
{ putchar(va_arg(args, int));
count++; }
else if (*format == 's')
{ char *str = va_arg(args, char *);
for (; *str; str++)
{ putchar(*str);
count++; }
}
}
else
{ putchar(*format);
count++; }
format++;
}
va_end(args);
return (count);
}