| 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 | * @file flag_f.c | ||
| 9 | * @brief The file containing the flag_f function | ||
| 10 | * @author Nicolas TORO | ||
| 11 | */ | ||
| 12 | |||
| 13 | #include "myprintf.h" | ||
| 14 | |||
| 15 | 12 | static char *my_get_str_float(double nb, formating_t *formating) | |
| 16 | { | ||
| 17 | 12 | long long int partie_entiere = ABS((int)nb); | |
| 18 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 11 times.
|
12 | double partie_d = ABS(nb - partie_entiere); |
| 19 | 12 | char *str_finale = malloc(sizeof(char) * 1000000); | |
| 20 | |||
| 21 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 11 times.
|
12 | if (nb < 0) { |
| 22 | 1 | my_strcat(str_finale, "-"); | |
| 23 | } | ||
| 24 | 12 | my_strcat(str_finale, my_str_nbr_long_long(partie_entiere)); | |
| 25 | 12 | precise_it_double(str_finale, formating, partie_d); | |
| 26 | 12 | format_it_double(str_finale, formating, nb); | |
| 27 | 12 | return str_finale; | |
| 28 | } | ||
| 29 | |||
| 30 | 12 | int flag_f(va_list list, formating_t *formating) | |
| 31 | { | ||
| 32 | 12 | double temp_nb = va_arg(list, double); | |
| 33 | 12 | char *temp = my_get_str_float(temp_nb, formating); | |
| 34 | |||
| 35 | 12 | return my_putstr_fd_free(temp, formating->fd); | |
| 36 | } | ||
| 37 |