-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
475 lines (405 loc) · 18.8 KB
/
main.c
File metadata and controls
475 lines (405 loc) · 18.8 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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dporhomo <dporhomo@student.42prague.com +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/12/02 12:15:48 by dporhomo #+# #+# */
/* Updated: 2025/12/10 15:27:47 by dporhomo ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
#include <stdio.h>
#include <limits.h>
// for tests with strings
static void test_char_str(void);
static void check_str(char *desc, char *fmt, char *arg);
static void check_char(char *desc, char *fmt, int arg);
// for tests with numbers
void test_signed_int(void);
// for tests with unsigned and hexadecimals
void test_hex_unsigned(void);
// for tests with pointers
static void test_ptr(void);
//1. Header defines all variables and constants
//2. Ft_printf detects % and initiates parsing
//3. Parsing reads formatting flags '-0. #'
//4. Converts %s and other specifiers
//5. Converts %d... for numbers and pointers
int main(void)
{
setbuf(stdout, NULL); // printf displays immediately, not after write()
// Chars and Str Tests
printf("\n------------- Test 1: Chars and Strings ----------------\n");
test_char_str();
printf("\n-------- Test 1: Chars and Strings completed -----------\n");
// Decimal Tests
printf("\n------------- Test 2: Decimals -------------------------\n");
test_signed_int();
printf("\n-------- Test 2: Decimals completed --------------------\n");
printf("\n------- Test 3: Unsigned and Hexadecimal ---------------\n");
test_hex_unsigned();
printf("\n--- Test 3: Unsigned and Hexadecimal completed ---------\n");
printf("\n------------- Test 4: Pointers --------------------------\n");
test_ptr();
printf("\n-------- Test 4: Pointers completed --------------------\n");
printf("\n-------- All tests have been completed -----------------\n");
printf("\n----------Live coding verification ---------------------\n");
//ft_printf("Hello %a World", "my awsome 42");
return (0);
}
static void test_char_str(void)
{
int ret_orig;
int ret_ft;
// [-0.* +#]
// --------- Testing Strings --------------------------------------
printf("\n=========== SIMPLE FULL STRIGS =============\n");
ret_orig = printf("|%s|\n", "This string.");
printf("ret_orig: %d\n", ret_orig);
ret_ft = ft_printf("|%s|\n", "This string.");
printf("ret_ft: %d\n", ret_ft);
printf("\n================ CHAR TESTS ================\n");
// With chars we have only left align '-' and width flags
// [-10c]
check_char("Basic Char", "%c", 'A');
check_char("Width 5", "%5c", 'B');
check_char("Left Align (-)", "%-5c", 'C');
// Note: %05c is undefined behavior for chars on some systems, skipping for now
printf("================ STRING TESTS ================\n");
// With strings we have: left align '-', width, precision flags
// [-10.3s]
check_str("Basic String", "%s", "Hello");
check_str("Width 10 (Right)", "%10s", "Hello");
check_str("Left Align (-) and Width 10 (Left)", "%-10s", "Hello");
check_str("Precision Truncate .3 on Ahoj", "%.3s", "Ahoj");
check_str("Precision .10 > Len of Ahoj", "%.10s", "Ahoj");
check_str("Width 10 + Precision .3 on Ahoj", "%10.3s", "Ahoj");
check_str("Width 10 + Precision .3 Left Align '-' on Ahoj", "%-10.3s", "Ahoj");
printf("================ EDGE CASES ================\n");
check_str("NULL String", "%s", NULL);
check_str("NULL w/ Width 10", "%10s", NULL);
check_str("NULL w/ Prec .3", "%.3s", NULL);
check_str("Empty String ''", "%s", "");
check_str("Empty w/ Width 5", "%5s", "");
printf("Test: Width * and arg 10 on 'Ahoj'\n");
ret_orig = printf("TEST: [%*s]\n", 10, "Ahoj");
ret_ft = ft_printf("TEST: [%*s]\n", 10, "Ahoj");
if (ret_orig == ret_ft)
printf(" ✅ Return Value Match: %d\n\n", ret_orig);
else
printf(" ❌ Return Value Mismatch! Orig: %d vs Mine: %d\n\n", ret_orig, ret_ft);
printf("Test: Width * and arg 10 and Left Indent '-' on 'Ahoj'\n");
ret_orig = printf("TEST: [%-*s]\n", 10, "Ahoj");
ret_ft = ft_printf("TEST: [%-*s]\n", 10, "Ahoj");
if (ret_orig == ret_ft)
printf(" ✅ Return Value Match: %d\n\n", ret_orig);
else
printf(" ❌ Return Value Mismatch! Orig: %d vs Mine: %d\n\n", ret_orig, ret_ft);
printf("\n======== c and s tests completed =====================\n");
}
static void check_char(char *desc, char *fmt, int arg)
{
int ret_orig;
int ret_ft;
printf("TEST: %s\n", desc);
printf("ORIG: [");
ret_orig = printf(fmt, arg);
printf("]\n");
printf("MINE: [");
ret_ft = ft_printf(fmt, arg);
printf("]\n");
if (ret_orig == ret_ft)
printf(" ✅ Return Value Match: %d\n\n", ret_orig);
else
printf(" ❌ Return Value Mismatch! Orig: %d vs Mine: %d\n\n", ret_orig, ret_ft);
}
static void check_str(char *desc, char *fmt, char *arg)
{
int ret_orig;
int ret_ft;
printf("TEST: %s\n", desc);
// 1. Run Original
printf("ORIG: [");
ret_orig = printf(fmt, arg);
printf("]\n");
// 2. Run Yours
printf("MINE: [");
ret_ft = ft_printf(fmt, arg);
printf("]\n");
// 3. Compare Return Values
if (ret_orig == ret_ft)
printf(" ✅ Return Value Match: %d\n\n", ret_orig);
else
printf(" ❌ Return Value Mismatch! Orig: %d vs Mine: %d\n\n", ret_orig, ret_ft);
}
void test_signed_int(void)
{
int ret_orig;
int ret_ft;
int val;
int neg;
int zero;
val = 42;
neg = -42;
zero = 0;
printf("\n============= INT (d / i) TESTS =========================\n");
// 1. Basic Tests
printf("============== Basic d and i test =========================\n");
ret_orig = printf("Expected numbers: %d, %i\n", 42, -123);
ret_ft = ft_printf("Ft_printf umbers: %d, %i\n", 42, -123);
if (ret_orig == ret_ft)
printf(" ✅ Return Value Match: %d\n\n", ret_orig);
else
printf(" ❌ Return Value Mismatch! Orig: %d vs Mine: %d\n\n", ret_orig, ret_ft);
//[- width, precision, 0 ' ' +]
printf("\n============== Full d and i tests =========================\n");
printf("--- 1. Basic Numbers ( 42 and -42)---\n");
// Positive
ret_orig = printf("ORIG: [%d]\n", val);
ret_ft = ft_printf("MINE: [%d]\n", val);
if (ret_orig != ret_ft) printf("❌ Mismatch! Orig: %d vs Mine: %d\n", ret_orig, ret_ft);
else printf(" ✅ Return Value Match: %d\n\n", ret_orig);
// Negative
ret_orig = printf("ORIG: [%i]\n", neg);
ret_ft = ft_printf("MINE: [%i]\n", neg);
if (ret_orig != ret_ft) printf("❌ Mismatch! Orig: %d vs Mine: %d\n", ret_orig, ret_ft);
else printf(" ✅ Return Value Match: %d\n\n", ret_orig);
// 2. Width Tests
printf("\n--- 2. Width Flags (ld) ---\n");
// Width < Len (Ignored)
printf("\n--- a. (1d) width less than len ---\n");
ret_orig = printf("ORIG: [%1d]\n", val);
ret_ft = ft_printf("MINE: [%1d]\n", val);
if (ret_orig != ret_ft) printf("❌ Mismatch! Orig: %d vs Mine: %d\n", ret_orig, ret_ft);
else printf(" ✅ Return Value Match: %d\n\n", ret_orig);
// Width > Len (Right Align)
printf("\n--- b. (10d) width greater than len ---\n");
ret_orig = printf("ORIG: [%10d]\n", val);
ret_ft = ft_printf("MINE: [%10d]\n", val);
if (ret_orig != ret_ft) printf("❌ Mismatch! Orig: %d vs Mine: %d\n", ret_orig, ret_ft);
else printf(" ✅ Return Value Match: %d\n\n", ret_orig);
// Width > Len (Left Align)
printf("\n--- c. (-10d) ---\n");
ret_orig = printf("ORIG: [%-10d]\n", val);
ret_ft = ft_printf("MINE: [%-10d]\n", val);
if (ret_orig != ret_ft) printf("❌ Mismatch! Orig: %d vs Mine: %d\n", ret_orig, ret_ft);
else printf(" ✅ Return Value Match: %d\n\n", ret_orig);
// 3. Precision Tests
printf("\n--- 3. Precision Flags ---\n");
// Precision > Len (Pad with 0)
printf("\n--- a. (.5d) ---\n");
ret_orig = printf("ORIG: [%.5d]\n", val);
ret_ft = ft_printf("MINE: [%.5d]\n", val);
if (ret_orig != ret_ft) printf("❌ Mismatch! Orig: %d vs Mine: %d\n", ret_orig, ret_ft);
else printf(" ✅ Return Value Match: %d\n\n", ret_orig);
// Precision > Len (Negative Number - 0s go AFTER sign)
printf("\n--- b. (.5d) negative ---\n");
ret_orig = printf("ORIG: [%.5d]\n", neg);
ret_ft = ft_printf("MINE: [%.5d]\n", neg);
if (ret_orig != ret_ft) printf("❌ Mismatch! Orig: %d vs Mine: %d\n", ret_orig, ret_ft);
else printf(" ✅ Return Value Match: %d\n\n", ret_orig);
// Precision < Len (Ignored for numbers)
printf("\n--- c. (.1d) smaller then Len ---\n");
ret_orig = printf("ORIG: [%.1d]\n", val);
ret_ft = ft_printf("MINE: [%.1d]\n", val);
if (ret_orig != ret_ft) printf("❌ Mismatch! Orig: %d vs Mine: %d\n", ret_orig, ret_ft);
else printf(" ✅ Return Value Match: %d\n\n", ret_orig);
// 4. Zero Padding Flag
printf("\n--- 4. Zero Flag ('0') ---\n");
// Zero padded width
printf("\n--- a. (05d) zero padded width ---\n");
ret_orig = printf("ORIG: [%05d]\n", val);
ret_ft = ft_printf("MINE: [%05d]\n", val);
if (ret_orig != ret_ft) printf("❌ Mismatch! Orig: %d vs Mine: %d\n", ret_orig, ret_ft);
else printf(" ✅ Return Value Match: %d\n\n", ret_orig);
// Zero padded negative (Sign must be first: -0042)
printf("\n--- b. (05d) zero padded width negative '-' must be printed first ---\n");
ret_orig = printf("ORIG: [%05d]\n", neg);
ret_ft = ft_printf("MINE: [%05d]\n", neg);
if (ret_orig != ret_ft) printf("❌ Mismatch! Orig: %d vs Mine: %d\n", ret_orig, ret_ft);
else printf(" ✅ Return Value Match: %d\n\n", ret_orig);
// Zero IGNORED if Precision is present (Undefined behavior in some,
// standard says ignore)
// Standard printf usually treats %.5d as priority over %05d ->
// spaces instead of 0 for width
//printf("\n--- c. (010.5d) .5d priority over 05d ---\n");
//ret_orig = printf("ORIG: [%010.5d]\n", val);
//ret_ft = ft_printf("MINE: [%010.5d]\n", val);
//if (ret_orig != ret_ft) printf("❌ Mismatch! Orig: %d vs Mine: %d\n", ret_orig, ret_ft);
//else printf(" ✅ Return Value Match: %d\n\n", ret_orig);
// Zero IGNORED if Left Align is present
//printf("\n--- d. (-05d) ignore zero if left aligned ---\n");
//ret_orig = printf("ORIG: [%-05d]\n", val);
//ret_ft = ft_printf("MINE: [%-05d]\n", val);
//if (ret_orig != ret_ft) printf("❌ Mismatch! Orig: %d vs Mine: %d\n", ret_orig, ret_ft);
//else printf(" ✅ Return Value Match: %d\n\n", ret_orig);
// 5. Sign Flags (+ and Space)
printf("\n--- 5. Sign Flags (+/space) ---\n");
// Plus Flag (Positive)
printf("\n--- a. (+d) ---\n");
ret_orig = printf("ORIG: [%+d]\n", val);
ret_ft = ft_printf("MINE: [%+d]\n", val);
if (ret_orig != ret_ft) printf("❌ Mismatch! Orig: %d vs Mine: %d\n", ret_orig, ret_ft);
else printf(" ✅ Return Value Match: %d\n\n", ret_orig);
// Plus Flag (Negative - should just be minus)
printf("\n--- b. (+d) on negative should be minus ---\n");
ret_orig = printf("ORIG: [%+d]\n", neg);
ret_ft = ft_printf("MINE: [%+d]\n", neg);
if (ret_orig != ret_ft) printf("❌ Mismatch! Orig: %d vs Mine: %d\n", ret_orig, ret_ft);
else printf(" ✅ Return Value Match: %d\n\n", ret_orig);
// Space Flag (Positive - single space)
printf("\n--- c. (' 'd) ---\n");
ret_orig = printf("ORIG: [% d]\n", val);
ret_ft = ft_printf("MINE: [% d]\n", val);
if (ret_orig != ret_ft) printf("❌ Mismatch! Orig: %d vs Mine: %d\n", ret_orig, ret_ft);
else printf(" ✅ Return Value Match: %d\n\n", ret_orig);
// Space Flag (Negative - ignored)
printf("\n--- d. (' 'd) on negative should be ignored---\n");
ret_orig = printf("ORIG: [% d]\n", neg);
ret_ft = ft_printf("MINE: [% d]\n", neg);
if (ret_orig != ret_ft) printf("❌ Mismatch! Orig: %d vs Mine: %d\n", ret_orig, ret_ft);
else printf(" ✅ Return Value Match: %d\n\n", ret_orig);
// Plus overrides Space
//printf("\n--- e. (+' 'd) plus overrided space---\n");
//ret_orig = printf("ORIG: [%+ d]\n", val);
//ret_ft = ft_printf("MINE: [%+ d]\n", val);
//if (ret_orig != ret_ft) printf("❌ Mismatch! Orig: %d vs Mine: %d\n", ret_orig, ret_ft);
//else printf(" ✅ Return Value Match: %d\n\n", ret_orig);
// 6. Extreme Edge Cases
printf("\n--- 6. Edge Cases ---\n");
// INT_MIN (Requires long casting inside your function to handle -(-2147483648))
printf("\n--- a. (d) INT_MIN ---\n");
ret_orig = printf("ORIG: [%d]\n", INT_MIN);
ret_ft = ft_printf("MINE: [%d]\n", INT_MIN);
if (ret_orig != ret_ft) printf("❌ Mismatch! Orig: %d vs Mine: %d\n", ret_orig, ret_ft);
else printf(" ✅ Return Value Match: %d\n\n", ret_orig);
// INT_MAX (Requires long casting inside your function to handle +(+2147483648))
printf("\n--- b. (d) INT_MAX ---\n");
ret_orig = printf("ORIG: [%d]\n", INT_MAX);
ret_ft = ft_printf("MINE: [%d]\n", INT_MAX);
if (ret_orig != ret_ft) printf("❌ Mismatch! Orig: %d vs Mine: %d\n", ret_orig, ret_ft);
else printf(" ✅ Return Value Match: %d\n\n", ret_orig);
// Zero Value
printf("\n--- c. (d) zero ---\n");
ret_orig = printf("ORIG: [%d]\n", zero);
ret_ft = ft_printf("MINE: [%d]\n", zero);
if (ret_orig != ret_ft) printf("❌ Mismatch! Orig: %d vs Mine: %d\n", ret_orig, ret_ft);
else printf(" ✅ Return Value Match: %d\n\n", ret_orig);
// The "Ghost" Zero: Precision 0 on Value 0 = Print NOTHING
printf("\n--- d. (.0d) Ghost zero: precision 0, value 0, print nothing ---\n");
ret_orig = printf("ORIG: [%.0d]\n", zero);
ret_ft = ft_printf("MINE: [%.0d]\n", zero);
if (ret_orig != ret_ft) printf("❌ Mismatch! Orig: %d vs Mine: %d\n", ret_orig, ret_ft);
else printf(" ✅ Return Value Match: %d\n\n", ret_orig);
// Ghost Zero with Width (Should print spaces)
printf("\n--- d. (5.0d) Ghost zero with width: precision 0, width 5, value 0, print padding 5 spaces ---\n");
ret_orig = printf("ORIG: [%5.0d]\n", zero);
ret_ft = ft_printf("MINE: [%5.0d]\n", zero);
if (ret_orig != ret_ft) printf("❌ Mismatch! Orig: %d vs Mine: %d\n", ret_orig, ret_ft);
else printf(" ✅ Return Value Match: %d\n\n", ret_orig);
}
void test_hex_unsigned(void)
{
int ret_orig, ret_ft;
unsigned int u_val = 42;
unsigned int hex_val = 255; // 0xff
printf("\n================ UNSIGNED & HEX TESTS ================\n");
// Unsigned Tests
printf("--- Unsigned Basic (u) u_val = 42 ---\n");
ret_orig = printf("ORIG: [%u]\n", u_val);
ret_ft = ft_printf("MINE: [%u]\n", u_val);
if (ret_orig != ret_ft) printf("❌ Mismatch! Orig: %d vs Mine: %d\n", ret_orig, ret_ft);
else printf(" ✅ Return Value Match: %d\n\n", ret_orig);
printf("--- Unsigned Negative Input (u) (Should print large positive) ---\n");
ret_orig = printf("ORIG: [%u]\n", -42);
ret_ft = ft_printf("MINE: [%u]\n", -42);
if (ret_orig != ret_ft) printf("❌ Mismatch! Orig: %d vs Mine: %d\n", ret_orig, ret_ft);
else printf(" ✅ Return Value Match: %d\n\n", ret_orig);
// Hex Tests
printf("\n--- Hex Basic (lower/upper) (x) (X) hex_val = 255 ---\n");
ret_orig = printf("ORIG: [%x] [%X]\n", hex_val, hex_val);
ret_ft = ft_printf("MINE: [%x] [%X]\n", hex_val, hex_val);
if (ret_orig != ret_ft) printf("❌ Mismatch! Orig: %d vs Mine: %d\n", ret_orig, ret_ft);
else printf(" ✅ Return Value Match: %d\n\n", ret_orig);
printf("\n--- Hex with zero Flag (0x) ---\n");
ret_orig = printf("ORIG: [%0x]\n", hex_val);
ret_ft = ft_printf("MINE: [%0x]\n", hex_val);
if (ret_orig != ret_ft) printf("❌ Mismatch! Orig: %d vs Mine: %d\n", ret_orig, ret_ft);
else printf(" ✅ Return Value Match: %d\n\n", ret_orig);
printf("\n--- Hex Hash Flag (#x) ---\n");
ret_orig = printf("ORIG: [%#x]\n", hex_val);
ret_ft = ft_printf("MINE: [%#x]\n", hex_val);
if (ret_orig != ret_ft) printf("❌ Mismatch! Orig: %d vs Mine: %d\n", ret_orig, ret_ft);
else printf(" ✅ Return Value Match: %d\n\n", ret_orig);
printf("\n--- Hex with Width (6x) ---\n");
// Should print 0x00ff (prefix counts towards width!)
ret_orig = printf("ORIG: [%6x]\n", hex_val);
ret_ft = ft_printf("MINE: [%6x]\n", hex_val);
if (ret_orig != ret_ft) printf("❌ Mismatch! Orig: %d vs Mine: %d\n", ret_orig, ret_ft);
else printf(" ✅ Return Value Match: %d\n\n", ret_orig);
printf("\n--- Hex with Width + Hash and Left Indent (-#6x) ---\n");
// Should print 0x00ff (prefix counts towards width!)
ret_orig = printf("ORIG: [%-#6x]\n", hex_val);
ret_ft = ft_printf("MINE: [%-#6x]\n", hex_val);
if (ret_orig != ret_ft) printf("❌ Mismatch! Orig: %d vs Mine: %d\n", ret_orig, ret_ft);
else printf(" ✅ Return Value Match: %d\n\n", ret_orig);
printf("\n--- Hex with Width and Left Indent (-6x) ---\n");
// Should print 0x00ff (prefix counts towards width!)
ret_orig = printf("ORIG: [%-6x]\n", hex_val);
ret_ft = ft_printf("MINE: [%-6x]\n", hex_val);
if (ret_orig != ret_ft) printf("❌ Mismatch! Orig: %d vs Mine: %d\n", ret_orig, ret_ft);
else printf(" ✅ Return Value Match: %d\n\n", ret_orig);
printf("\n--- Hex with Hash + Width (#6x) ---\n");
// Should print 0x00ff (prefix counts towards width!)
ret_orig = printf("ORIG: [%#6x]\n", hex_val);
ret_ft = ft_printf("MINE: [%#6x]\n", hex_val);
if (ret_orig != ret_ft) printf("❌ Mismatch! Orig: %d vs Mine: %d\n", ret_orig, ret_ft);
else printf(" ✅ Return Value Match: %d\n\n", ret_orig);
printf("\n--- Hex with Hash + Width (06x) ---\n");
// Should print 0x00ff (prefix counts towards width!)
ret_orig = printf("ORIG: [%06x]\n", hex_val);
ret_ft = ft_printf("MINE: [%06x]\n", hex_val);
if (ret_orig != ret_ft) printf("❌ Mismatch! Orig: %d vs Mine: %d\n", ret_orig, ret_ft);
else printf(" ✅ Return Value Match: %d\n\n", ret_orig);
printf("\n--- Hex Zero Value with Hash (#x) (No prefix) ---\n");
ret_orig = printf("ORIG: [%#x]\n", 0);
ret_ft = ft_printf("MINE: [%#x]\n", 0);
if (ret_orig != ret_ft) printf("❌ Mismatch! Orig: %d vs Mine: %d\n", ret_orig, ret_ft);
else printf(" ✅ Return Value Match: %d\n\n", ret_orig);
}
static void test_ptr(void)
{
int ret_orig;
int ret_ft;
int a;
int *ptr;
a = 42;
ptr = &a;
printf("\n================ POINTER TESTS ================\n");
// 1. Valid Pointer
printf("--- Valid Pointer [p]---\n");
ret_orig = printf("ORIG: [%p]\n", ptr);
ret_ft = ft_printf("MINE: [%p]\n", ptr);
if (ret_orig != ret_ft) printf("❌ Mismatch! Orig: %d vs Mine: %d\n", ret_orig, ret_ft);
else printf(" ✅ Return Value Match: %d\n\n", ret_orig);
// 2. NULL Pointer
printf("\n--- NULL Pointer [p] ---\n");
ret_orig = printf("ORIG: [%p]\n", NULL);
ret_ft = ft_printf("MINE: [%p]\n", NULL);
if (ret_orig != ret_ft) printf("❌ Mismatch! Orig: %d vs Mine: %d\n", ret_orig, ret_ft);
else printf(" ✅ Return Value Match: %d\n\n", ret_orig);
// 3. Pointer with Width
printf("\n--- Pointer with Width [20p]---\n");
ret_orig = printf("ORIG: [%20p]\n", ptr);
ret_ft = ft_printf("MINE: [%20p]\n", ptr);
if (ret_orig != ret_ft) printf("❌ Mismatch! Orig: %d vs Mine: %d\n", ret_orig, ret_ft);
else printf(" ✅ Return Value Match: %d\n\n", ret_orig);
// 4. Pointer with Width and Left Align
printf("\n--- Pointer with Width [-20p]---\n");
ret_orig = printf("ORIG: [%-20p]\n", ptr);
ret_ft = ft_printf("MINE: [%-20p]\n", ptr);
if (ret_orig != ret_ft) printf("❌ Mismatch! Orig: %d vs Mine: %d\n", ret_orig, ret_ft);
else printf(" ✅ Return Value Match: %d\n\n", ret_orig);
}