-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.c
More file actions
191 lines (147 loc) · 6.6 KB
/
test.c
File metadata and controls
191 lines (147 loc) · 6.6 KB
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
#include <stdio.h>
#include <limits.h>
#include "printf.h"
/*
int main(void)
{
char *str;
str = "Esta es mi string";
ft_printf("\nMy numero de caracteres es %d", ft_printf("This is a char: %c\nan string: %s\na int: %d\na unsigned int: %u\na %% symbol\na hex lower %x\na hex upper %X\na pointer %p\nand a break%", 'a', "testing string", 3891281, 2147483647, 590, 590, str));
write(1, "\n\n", 2);
printf("\nMy numero de caracteres es %d", printf("This is a char: %c\nan string: %s\na int: %d\na unsigned int: %u\na %% symbol\na hex lower %x\na hex upper %X\na pointer %p\nand a break", 'a', "testing string", 3891281, 2147483647, 590, 590, str));
return (0);
}
*/
int main()
{
int n_ft;
int n;
char str[5] = "hola";
//! CARÁCTERES
printf("---------------------------\n");
printf("TEXTO SIN FORMATO\n");
n_ft = ft_printf("esto es una prueba"); printf(" |FT: %d\n",n_ft);
n = printf("esto es una prueba"); printf(" | : %d\n",n);
printf("---------------------------\n");
printf("CARÁCTERES\n");
n_ft = ft_printf("%c %c %c %c", 'H','O','L','A'); printf(" | Carácteres FT: %d\n",n_ft);
n = printf("%c %c %c %c", 'H','O','L','A'); printf(" | Carácteres: %d\n",n);
n_ft = ft_printf("%c", 126); printf(" | Carácteres FT: %d\n",n_ft);
n = printf("%c", 126); printf(" | Carácteres: %d\n",n);
n_ft = ft_printf("%c %c %c", '0',0,'1'); printf(" | Carácteres FT: %d\n",n_ft);
n = printf("%c %c %c", '0',0,'1'); printf(" | Carácteres: %d\n",n);
//! STRINGS
printf("---------------------------\n");
printf("STRINGS\n");
char *ptr = str;
n_ft = ft_printf("%s",ptr); printf(" | Carácteres FT: %d\n",n_ft);
n = printf("%s",ptr); printf(" | Carácteres: %d\n",n);
ptr = NULL;
n_ft = ft_printf("%s",ptr); printf(" | Carácteres FT: %d\n",n_ft);
n = printf("%s",ptr); printf(" | Carácteres: %d\n",n);
//! PUNTEROS
printf("---------------------------\n");
printf("PUNTEROS\n");
char *my_ptr = NULL;
n_ft = ft_printf("%p",my_ptr); printf(" | Carácteres FT: %d\n",n_ft);
n = printf("%p",my_ptr); printf(" | Carácteres: %d\n",n);
my_ptr = str;
n_ft = ft_printf("%p",my_ptr); printf(" | Carácteres FT: %d\n",n_ft);
n = printf("%p",my_ptr); printf(" | Carácteres: %d\n",n);
//! DECIMALES CON SIGNO
printf("---------------------------\n");
printf("DECIMALES CON SIGNO\n");
n_ft = ft_printf("%d",2147483647); printf(" | Carácteres FT: %d\n",n_ft);
n = printf("%d",2147483647); printf(" | Carácteres: %d\n",n);
//! DECIMALES SIN SIGNO
printf("---------------------------\n");
printf("DECIMALES SIN SIGNO\n");
n_ft = ft_printf("%u",-2147483647); printf(" | Carácteres FT: %d\n",n_ft);
n = printf("%u",-2147483647); printf(" | Carácteres: %d\n",n);
//! ENTEROS
printf("---------------------------\n");
printf("ENTEROS\n");
n_ft = ft_printf("%i",-2147483647); printf(" | Carácteres FT: %d\n",n_ft);
n = printf("%i",-2147483647); printf(" | Carácteres: %d\n",n);
//! HEXADECIMALES
printf("---------------------------\n");
printf("HEXADECIMALES\n");
unsigned int hex = 0;
n_ft = ft_printf("x: %x | X: %X",hex,hex); printf(" | Carácteres FT: %d\n",n_ft);
n = printf("x: %x | X: %X",hex,hex); printf(" | Carácteres: %d\n",n);
hex = 4294967295;
n_ft = ft_printf("x: %x | X: %X",hex,hex); printf(" | Carácteres FT: %d\n",n_ft);
n = printf("x: %x | X: %X",hex,hex); printf(" | Carácteres: %d\n",n);
//! PORCENTAJES
printf("---------------------------\n");
printf("PORCENTAJES\n");
n_ft = ft_printf(" %% "); printf(" | Carácteres FT: %d\n",n_ft);
n = printf(" %% "); printf(" | Carácteres: %d\n",n);
//! Diferenciador erroneo
printf("---------------------------\n");
printf("DIFERENCIADOR\n");
n_ft = ft_printf("Especificador invalido: %z", 42); printf(" | Carácteres FT: %d\n",n_ft);
n = printf("Especificador invalido: %z", 42); printf(" | Carácteres: %d\n",n);
//! % solo al final de string
printf("---------------------------\n");
printf("%% al final de la string\n");
n_ft = ft_printf("Al final hay un %"); printf(" | Carácteres FT: %d\n",n_ft);
n = printf("Al final hay un %"); printf(" | Carácteres: %d\n",n);
//! % en medio de una string de string
printf("---------------------------\n");
printf("%% en medio de una string\n");
n_ft = ft_printf("Al final habia un % , pero ahora una string: %s", "String aqui"); printf(" | Carácteres FT: %d\n",n_ft);
n = printf("Al final habia un % , pero ahora una string: %s", "String aqui"); printf(" | Carácteres: %d\n",n);
//! No hay string
printf("---------------------------\n");
printf("String vacia\n");
n_ft = ft_printf(""); printf(" | Carácteres FT: %d\n",n_ft);
n = printf(""); printf(" | Carácteres: %d\n",n);
//! Mas argumentos que especificadores
printf("---------------------------\n");
printf("Especificadores de mas\n");
n_ft = ft_printf("Hay especificadores de mas: %s, %s", str); printf(" | Carácteres FT: %d\n",n_ft);
n = printf("Hay especificadores de mas: %s, %s", str); printf(" | Carácteres: %d\n",n);
//! Menos argumentos que especificadores
printf("---------------------------\n");
printf("Especificadores de menos\n");
n_ft = ft_printf("Hay especificadores de menos: %s", str, "Argumento de mas"); printf(" | Carácteres FT: %d\n",n_ft);
n = printf("Hay especificadores de menos: %s", str, "Argumento de mas"); printf(" | Carácteres: %d\n",n);
//! Espeficicador erroneo
printf("---------------------------\n");
printf("Especificador erroneo\n");
n_ft = ft_printf("Especificador erroneo: %s", 0); printf(" | Carácteres FT: %d\n",n_ft);
n = printf("Especificador erroneo: %s", 0); printf(" | Carácteres: %d\n",n);
//! Extra test
write(1, "My ft\n", 7);
ft_printf(" %p %p ", LONG_MIN, LONG_MAX);
write(1, "\n", 1);
ft_printf(" %x ", LONG_MAX);
write(1, "\n", 1);
ft_printf(" %x ", ULONG_MAX);
write(1, "\n", 1);
ft_printf(" %x ", 9223372036854775807LL);
write(1, "\n", 1);
ft_printf(" %x %x %x %x %x %x %x", INT_MAX, INT_MIN, LONG_MAX, LONG_MIN, ULONG_MAX, 0, -42);
write(1, "\n", 1);
ft_printf(" %X ", LONG_MAX);
write(1, "\n", 1);
ft_printf(" %X ", ULONG_MAX);
write(1, "\n", 1);
ft_printf(" %X ", 9223372036854775807LL);
write(1, "\n", 1);
ft_printf(" %X %X %X %X %X %X %X", INT_MAX, INT_MIN, LONG_MAX, LONG_MIN, ULONG_MAX, 0, -42);
write(1, "\n", 1);
printf("Original printf\n");
printf(" %p %p\n", LONG_MIN, LONG_MAX);
printf(" %x\n", LONG_MAX);
printf(" %x\n", ULONG_MAX);
printf(" %x\n", 9223372036854775807LL);
printf(" %x %x %x %x %x %x %x\n", INT_MAX, INT_MIN, LONG_MAX, LONG_MIN, ULONG_MAX, 0, -42);
printf(" %X\n", LONG_MAX);
printf(" %X\n", ULONG_MAX);
printf(" %X\n", 9223372036854775807LL);
printf(" %X %X %X %X %X %X %X\n", INT_MAX, INT_MIN, LONG_MAX, LONG_MIN, ULONG_MAX, 0, -42);
system("leaks -q a.out");
return (0);
}