-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_printf.c
50 lines (47 loc) · 956 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
#include "main.h"
/**
* _printf - A function that produces output according to a format.
* A mimic of normal prinft C function.
* @format: A Formatted character string.
*
* Return: # Number of printed characters. on (Succeess).
* # -1 otherwise, on (Failure).
*/
int _printf(const char *format, ...)
{
va_list list;
int *charCount;
int count;
count = 0;
charCount = &count;
if (!format || (*(format + 0) == '%' && !*(format + 1)))
return (-1);
if (*(format + 0) == '%' && (*(format + 1) == ' ' && !*(format + 2)))
return (-1);
if (*(format + 0) == '%' && (*(format + 1) == ' '))
{
while (*(format + 1) == ' ')
format++;
format++;
}
va_start(list, format);
while (*format)
{
switch (_fetch_specifier(*format))
{
case 0:
{
_handle_fmt(list, ++format, charCount);
break;
}
default:
{
*charCount += _putchar(*format);
break;
}
}
++format;
}
va_end(list);
return (count);
}