-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path_printf.c
More file actions
54 lines (49 loc) · 863 Bytes
/
_printf.c
File metadata and controls
54 lines (49 loc) · 863 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
52
53
54
#include <stdlib.h>
#include <stdarg.h>
#include "holberton.h"
/**
* _printf - function that print characters for condicional character
* @format: char pointer
*
* Return: integer equal to lenght the print
*/
int _printf(const char *format, ...)
{
va_list pa;
const char *p;
int num = 0;
if (format == NULL)
return (-1);
va_start(pa, format);
for (p = format; *p; p++)
{
if (*p == '%')
{
switch (*++p)
{
case 's':
num = num + print_string(pa);
break;
case 'c':
num = num + print_character(pa);
break;
case '%':
num = num + 1;
_putchar('%');
break;
case '\0':
return (-1);
case 'i':
case 'd':
num = num + print_integer(pa);
break;
default:
_putchar('%'), _putchar(*p), num = num + 2;
}
}
else
_putchar(*p), num++;
}
va_end(pa);
return (num);
}