| 1 | #include <stdlib.h> |
| 2 | #include <stdio.h> |
| 3 | |
| 4 | #include "array.h" |
| 5 | #include "utils.h" |
| 6 | #include "io.h" |
| 7 | |
| 8 | int main() { |
| 9 | int* tab = NULL; |
| 10 | unsigned tab_size = 0; |
| 11 | int errno = 0; |
| 12 | int choice = 0; |
| 13 | |
| 14 | printf("=== Saisie initiale ===\n\n"); |
| 15 | tab = prompt_array(tab, &tab_size); |
| 16 | |
| 17 | do { |
| 18 | display_choice_menu(); |
| 19 | errno = prompt_value("Choix?", &choice); |
| 20 | handle_prompt_error(errno, tab); |
| 21 | if (1 > choice || 8 < choice) { |
| 22 | printf("\nFaire un choix compris entre 1 et 8\n"); |
| 23 | continue; |
| 24 | } |
| 25 | switch (choice) { |
| 26 | case 1: |
| 27 | tab = do_concat(tab, &tab_size); |
| 28 | break; |
| 29 | case 2: |
| 30 | do_sort(tab, tab_size); |
| 31 | break; |
| 32 | case 3: |
| 33 | display_array(tab, tab_size); |
| 34 | break; |
| 35 | case 4: |
| 36 | do_count(tab, tab_size); |
| 37 | break; |
| 38 | case 5: |
| 39 | printf("\nLe nombre d'entiers pairs dans le tableau est %d\n", count_tab_criteria(tab, tab_size, is_even)); |
| 40 | break; |
| 41 | case 6: |
| 42 | printf("\nLe nombre d'entiers impairs dans le tableau est %d\n", count_tab_criteria(tab, tab_size, is_odd)); |
| 43 | break; |
| 44 | case 7: |
| 45 | do_resize(tab, &tab_size); |
| 46 | break; |
| 47 | default: |
| 48 | /* do nothing, unused code path */ |
| 49 | break; |
| 50 | } |
| 51 | } while (choice != 8); |
| 52 | |
| 53 | free_tab(tab); |
| 54 | exit(EXIT_SUCCESS); |
| 55 | } |