-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_printf.c
More file actions
49 lines (48 loc) · 850 Bytes
/
_printf.c
File metadata and controls
49 lines (48 loc) · 850 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
#include "main.h"
/**
* _printf - function to print formatted string
* @format: string
* Return: int
*/
int _printf(const char *format, ...)
{
va_list ap;
char *stringstart;
int cntr = 0;
const char *x = printstr(format), *temp;
if (format == NULL)
return (-1);
va_start(ap, format);
cntr += (x - format);
while (*x != '\0')
{
x++;
switch (*x)
{
case ('c'):
cntr += printchar(va_arg(ap, int));
break;
case ('%'):
write(1, x, 1);
cntr++;
break;
case ('s'):
stringstart = va_arg(ap, char *);
if (stringstart == NULL)
return (-1);
cntr += (printstringspecifier(stringstart) - stringstart);
break;
case ('i'):
case ('d'):
cntr += printnum(va_arg(ap, int));
break;
default:
return (-1);
}
x++;
temp = printstr(x);
cntr += (temp - x);
x = temp;
}
return (cntr);
}