X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=TP_13%2Fexo1%2Fsrc%2Fmain.c;h=ef4d5455c32177aba07a6eff8f7af458d9931fd1;hb=59941dc1cf415077fbfbde8b313e52e8f3fc6fe5;hp=9f23749fbc3b2def57ca83457ac762d44e426e0a;hpb=34dd19e9551e120279afde8d75a1cb51181d7794;p=TD_C.git diff --git a/TP_13/exo1/src/main.c b/TP_13/exo1/src/main.c index 9f23749..ef4d545 100644 --- a/TP_13/exo1/src/main.c +++ b/TP_13/exo1/src/main.c @@ -7,19 +7,48 @@ int main() { int* tab = NULL; - const unsigned tab_size = 11; - tab = create_tab(tab, tab_size); - - printf("%d\n", tab_size); - - display_array(tab, tab_size); - - const unsigned tab_new_size = 20; - tab = resize_tab(tab, tab_new_size); - - printf("%d\n", tab_new_size); - - display_array(tab, tab_new_size); + unsigned tab_size = 0; + int errno = 0; + int choice = 0; + + printf("=== Saisie initiale ===\n\n"); + tab = prompt_array(tab, &tab_size); + + do { + display_choice_menu(); + errno = prompt_value("Choix?", &choice); + handle_prompt_error(errno); + if (1 > choice || 8 < choice) { + printf("\nFaire un choix compris entre 1 et 8\n"); + continue; + } + switch (choice) { + case 1: + tab = do_concat(tab, &tab_size); + break; + case 2: + do_sort(tab, tab_size); + break; + case 3: + display_array(tab, tab_size); + break; + case 4: + do_count(tab, tab_size); + break; + case 5: + printf("\nLe nombre d'entiers pairs dans le tableau est %d\n", count_tab_criteria(tab, tab_size, is_even)); + break; + case 6: + printf("\nLe nombre d'entiers impairs dans le tableau est %d\n", count_tab_criteria(tab, tab_size, is_odd)); + break; + case 7: + do_resize(tab, &tab_size); + break; + default: + /* do nothing, unused code path */ + break; + } + } while (choice != 8); free_tab(tab); exit(EXIT_SUCCESS);