Line | Branch | Exec | Source |
---|---|---|---|
1 | /* | ||
2 | ** EPITECH PROJECT, 2023 | ||
3 | ** my_printf | ||
4 | ** File description: | ||
5 | ** Flag to print a %n (store a int) | ||
6 | */ | ||
7 | /** | ||
8 | * @file flag_n.c | ||
9 | * @brief The file containing the flag_n function | ||
10 | * @author Nicolas TORO | ||
11 | */ | ||
12 | |||
13 | #include "myprintf.h" | ||
14 | |||
15 | 1 | static void signed_char(va_list list, int len) | |
16 | { | ||
17 | 1 | signed char *variable_char = va_arg(list, signed char *); | |
18 | |||
19 | 1 | *variable_char = len; | |
20 | 1 | } | |
21 | |||
22 | 1 | static void short_int(va_list list, int len) | |
23 | { | ||
24 | 1 | short *variable_short = va_arg(list, short *); | |
25 | |||
26 | 1 | *variable_short = len; | |
27 | 1 | } | |
28 | |||
29 | 2 | static void basic_int(va_list list, int len) | |
30 | { | ||
31 | 2 | int *variable_int = va_arg(list, int *); | |
32 | |||
33 | 2 | *variable_int = len; | |
34 | 2 | } | |
35 | |||
36 | 1 | static void long_int(va_list list, int len) | |
37 | { | ||
38 | 1 | long int *variable_long = va_arg(list, long *); | |
39 | |||
40 | 1 | *variable_long = len; | |
41 | 1 | } | |
42 | |||
43 | 1 | static void long_long_int(va_list list, int len) | |
44 | { | ||
45 | 1 | long long int *variable_long_long = va_arg(list, long long *); | |
46 | |||
47 | 1 | *variable_long_long = len; | |
48 | 1 | } | |
49 | |||
50 | 4 | static void basic_size_t(va_list list, int len) | |
51 | { | ||
52 | 4 | size_t *variable_size_t = va_arg(list, size_t *); | |
53 | |||
54 | 4 | *variable_size_t = len; | |
55 | 4 | } | |
56 | |||
57 | 10 | int flag_n(va_list list, formating_t *formating, int len) | |
58 | { | ||
59 | 10 | void (*specify[])(va_list, int) = {&long_int, &long_long_int, | |
60 | &short_int, &signed_char, &basic_size_t, | ||
61 | &basic_size_t, &basic_size_t, &basic_size_t}; | ||
62 | |||
63 |
2/2✓ Branch 0 taken 8 times.
✓ Branch 1 taken 2 times.
|
10 | if (formating->id_sp != -1) { |
64 | 8 | specify[formating->id_sp](list, len); | |
65 | } else { | ||
66 | 2 | basic_int(list, len); | |
67 | } | ||
68 | 10 | return 0; | |
69 | } | ||
70 |