-
Notifications
You must be signed in to change notification settings - Fork 0
/
_printf.c
78 lines (76 loc) · 1.32 KB
/
_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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include "main.h"
/**
* _printf - function
* @format: format
* Return: int
*/
int _printf(const char *format, ...)
{
const char *text = format;
int len = strlen(format);
int lenchar = 0;
int i;
int i2;
int m;
char str;
int skiptwo = 0;
va_list ptr;
char formats[] = {'c', 's', '%', 'd', 'i'};
va_start(ptr, format);
for (i = 0; i < len; i++)
{
str = format[i];
for (i2 = 0; i2 < 5; i2++)
{
if (text[i] == '%' && text[i + 1] == formats[i2] && formats[i2] == 'c')
{
one(ptr);
lenchar++;
skiptwo = 1;
}
else if (text[i] == '%' && text[i + 1] == formats[i2] && formats[i2] == 's')
{
m = four(ptr);
lenchar = lenchar + m;
skiptwo = 1;
}
else if (text[i] == '%' && text[i + 1] == formats[i2] && formats[i2] == '%')
{
three(ptr);
lenchar++;
skiptwo = 1;
}
else if (text[i] == '%' && text[i + 1] == formats[i2] && formats[i2] == 'd')
{
five(ptr);
lenchar++;
skiptwo = 1;
}
else if (text[i] == '%' && text[i + 1] == formats[i2] && formats[i2] == 'i')
{
five(ptr);
lenchar++;
skiptwo = 1;
}
else
{
two(ptr);
}
}
if (skiptwo == 0)
{
putchar(str);
lenchar++;
}
else
{
i = i + 1;
skiptwo = 0;
}
}
return (lenchar);
}