-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path0-printf.c
More file actions
50 lines (48 loc) · 954 Bytes
/
Copy path0-printf.c
File metadata and controls
50 lines (48 loc) · 954 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
#include "main.h"
/**
* _printf - Prints output acording to an input format.
* @format: Pointer to a formated string
*
* Return: number of characters printed to the screen
*/
int _printf(const char *format, ...)
{
int i;
va_list next;
count = 0;
if (!format || (format[0] == '%' && !(format[1])))
return (-1);
if (format[0] == '%' && format[1] == ' ' && !format[2])
return (-1);
va_start(next, format);
for (i = 0; format[i] != '\0'; i++)
{
if (format[i] == '%')
{
if ((format[i + 1] == 'd' || format[i + 1] == 'i'))
{
print_number(va_arg(next, int));
i++;
continue;
} else if (format[i + 1] == 'c')
{
_putchar(va_arg(next, int));
i++;
continue;
} else if (format[i + 1] == 's')
{
_puts(va_arg(next, char *));
i++;
continue;
} else if (format[i + 1] == '%')
{
_putchar('%');
i++;
continue;
}
}
_putchar(format[i]);
}
va_end(next);
return (count);
}