TP 13 exo1: Give more explicits name to callbacks
[TD_C.git] / TP_13 / exo1 / lib / io.c
index 989e746aa237cd90d18c0b3861427deefd5f1bf2..e5a300070d24305638d8f140b866b480950a93d6 100644 (file)
@@ -28,7 +28,10 @@ void display_choice_menu() {
     printf("2) Trier le tableau.\n");
     printf("3) Afficher le tableau.\n");
     printf("4) Compter le nombre d'occurence d'un entier dans le tableau.\n");
-    printf("5) Quitter.\n");
+    printf("5) Compter le nombre d'entiers pairs dans le tableau.\n");
+    printf("6) Compter le nombre d'entiers impairs dans le tableau.\n");
+    printf("7) Redimensionner le tableau.\n");
+    printf("8) Quitter.\n");
 }
 
 int* do_concat(int array[], unsigned* size) {
@@ -47,7 +50,7 @@ void do_sort(int array[], unsigned size) {
     int errno = 0;
     int choice = 0;
     bool done = false;
-    criteria_cb criteria;
+    s_criteria_cb sort_criteria;
 
     printf("\n=== Menu de tri ===\n\n");
     printf("1) Croissant.\n");
@@ -65,22 +68,23 @@ void do_sort(int array[], unsigned size) {
     } while (!done);
     switch (choice) {
         case 1:
-            criteria = ascending;
+            sort_criteria = ascending;
             break;
         case 2:
-            criteria = descending;
+            sort_criteria = descending;
             break;
         case 3:
-            criteria = ascending_and_even;
+            sort_criteria = ascending_and_even;
             break;
         case 4:
-            criteria = ascending_and_odd;
+            sort_criteria = ascending_and_odd;
             break;
         default:
-            criteria = ascending;
+            /* sort ascending by default, unused code path */
+            sort_criteria = ascending;
             break;
     }
-    sort_tab(array, size, criteria);
+    sort_tab(array, size, sort_criteria);
 }
 
 void do_count(int array[], unsigned size) {
@@ -92,6 +96,18 @@ void do_count(int array[], unsigned size) {
     printf("La valeur %d est presente %d fois dans le tableau\n", search_value, count_tab_element(array, size, search_value));
 }
 
+void do_resize(int array[], unsigned* old_size) {
+    int errno = 0;
+    unsigned new_size = 0;
+
+    errno = prompt_value("\nNouvelle taille?", (int*)&new_size);
+    handle_prompt_error(errno);
+    /* FIXME: one should able the set the array new content if new_size > *old_size 
+     * for now, new values are zeroed */
+    array = resize_tab(array, *old_size, new_size);
+    *old_size = new_size;
+}
+
 void display_array(int array[], unsigned size) {
     if (array != NULL) {
         printf("\n--array begin--\n");