8 int prompt_value(const char* msg
, int* result
) {
10 int retVal
= scanf("%d", result
);
11 return (retVal
== 1) ? 0 : 1;
14 int* prompt_array(int array
[], unsigned* size
) {
15 int errno
= prompt_value("Taille du tableau?", (int*)size
);
16 array
= create_tab(array
, *size
);
17 for (unsigned i
= 0; i
< *size
; i
++) {
18 errno
+= prompt_value("Valeur?", &array
[i
]);
20 /* error might have occured */
21 handle_prompt_error(errno
);
25 void display_choice_menu() {
26 printf("\n=== Menu ===\n\n");
27 printf("1) Saisir puis concatener un autre tableau.\n");
28 printf("2) Trier le tableau.\n");
29 printf("3) Afficher le tableau.\n");
30 printf("4) Compter le nombre d'occurence d'un entier dans le tableau.\n");
31 printf("5) Quitter.\n");
34 int* do_concat(int array
[], unsigned* size
) {
35 int* tab_to_concat
= NULL
;
36 unsigned tab_to_concat_size
= 0;
37 printf("\n=== Saisie d'un tableau ===\n\n");
38 tab_to_concat
= prompt_array(tab_to_concat
, &tab_to_concat_size
);
39 int* tab_concat
= concat_tab(array
, *size
, tab_to_concat
, tab_to_concat_size
);
40 *size
+= tab_to_concat_size
;
42 free_tab(tab_to_concat
);
46 void do_sort(int array
[], unsigned size
) {
52 printf("\n=== Menu de tri ===\n\n");
53 printf("1) Croissant.\n");
54 printf("2) Decroissant.\n");
55 printf("3) Croissant pairs en premier.\n");
56 printf("4) Croissant impairs en premier.\n");
58 errno
= prompt_value("Choix?", &choice
);
59 handle_prompt_error(errno
);
61 if (1 > choice
|| 4 < choice
) {
62 printf("\nFaire un choix compris entre 1 et 4\n");
71 criteria
= descending
;
74 criteria
= ascending_and_even
;
77 criteria
= ascending_and_odd
;
83 sort_tab(array
, size
, criteria
);
86 void do_count(int array
[], unsigned size
) {
90 errno
= prompt_value("\nValeur a chercher?", &search_value
);
91 handle_prompt_error(errno
);
92 printf("La valeur %d est presente %d fois dans le tableau\n", search_value
, count_tab_element(array
, size
, search_value
));
95 void display_array(int array
[], unsigned size
) {
97 printf("\n--array begin--\n");
98 for (unsigned i
= 0; i
< size
; i
++) {
99 printf("value in array at index[%d]=%d\n", i
, array
[i
]);
101 printf("--array end--\n");
103 printf("\n--array NULL--\n");