Line | Branch | Exec | Source |
---|---|---|---|
1 | /* | ||
2 | ** EPITECH PROJECT, 2023 | ||
3 | ** my_printf | ||
4 | ** File description: | ||
5 | ** Flag to print a %f (a double) | ||
6 | */ | ||
7 | |||
8 | #include <stdarg.h> | ||
9 | #include <stddef.h> | ||
10 | #include <stdlib.h> | ||
11 | #include "my.h" | ||
12 | #include "myformats.h" | ||
13 | |||
14 | 12 | static char *my_get_str_float(double nb, formating_t *formating) | |
15 | { | ||
16 | 12 | long long int partie_entiere = ABS((int)nb); | |
17 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 11 times.
|
12 | double partie_d = ABS(nb - partie_entiere); |
18 | 12 | char *str_finale = MALLOC(sizeof(char) * 1000000); | |
19 | |||
20 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 11 times.
|
12 | if (nb < 0) { |
21 | 1 | my_strcat(str_finale, "-"); | |
22 | } | ||
23 | 12 | my_strcat(str_finale, my_str_nbr_long_long(partie_entiere)); | |
24 | 12 | precise_it_double(str_finale, formating, partie_d); | |
25 | 12 | format_it_double(str_finale, formating, nb); | |
26 | 12 | return my_strdup(str_finale); | |
27 | } | ||
28 | |||
29 | 12 | int flag_f(va_list list, formating_t *formating) | |
30 | { | ||
31 | 12 | double temp_nb = va_arg(list, double); | |
32 | 12 | char *temp = my_get_str_float(temp_nb, formating); | |
33 | |||
34 | 12 | my_putstrf(formating->fd, temp); | |
35 | 12 | return my_strlen(temp); | |
36 | } | ||
37 |