-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlibprintj.c
64 lines (52 loc) · 1.1 KB
/
libprintj.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
#include "libprintj.h"
int main()
{
printj("\nString: %s / Char: %c / Int: %d / This doesn't count: %%", "hello world", 'x', 1234);
return 0;
}
void printj (char* format, ...)
{
va_list arg;
va_start(arg, format);
int parameters = libprintj_count(format);
printf("\nCantidad: %d", parameters);
// char *str = va_arg(arg, char *);
// char ltr = va_arg(arg, char);
// int num = va_arg(arg, int);
char *text;
int text_pos = 0;
while(*format)
{
printf("\n%c", format[text_pos]);
text[text_pos] = format[text_pos];
text_pos++;
format++;
}
text[text_pos] = '\0';
va_end(arg);
printf("%s", text);
printf("%s", format);
}
int libprintj_count (char* format)
{
char type[6] = {'s', 'c', 'd', 'f', '\0'};
int counter = 0;
int txt_length = strlen (format);
int arr_lenght = strlen (type);
int i, j;
for(i=0; i<txt_length; i++)
{
if(format[i] == '%')
{
for(j=0; j<arr_lenght; j++)
{
if(format[i+1]==type[j])
{
counter++;
break;
}
}
}
}
return counter;
}