TP 13 exo1: Implement more asked features and test them
[TD_C.git] / TP_13 / exo1 / lib / io.c
1 #include <stdio.h>
2
3 #include "io.h"
4 #include "array.h"
5
6 int prompt_value(const char* msg, int* result) {
7 puts(msg);
8 int retVal = scanf("%d", result);
9 return (retVal == 1) ? 0 : 1;
10 }
11
12 int* prompt_array(int array[], unsigned* size) {
13 int errno = prompt_value("Taille du tableau?", (int*)size);
14 array = create_tab(array, *size);
15 for (unsigned i = 0; i < *size; i++) {
16 errno += prompt_value("Valeur?", &array[i]);
17 }
18 if (errno == 0) {
19 return array;
20 } else {
21 return NULL;
22 }
23 }
24
25 void display_array(int* array, int size) {
26 if (array != NULL) {
27 printf("--array begin--\n");
28 for (int i = 0; i < size; i++) {
29 printf("value in array at index[%d]=%d\n", i, array[i]);
30 }
31 printf("--array end--\n");
32 } else {
33 printf("--array NULL--\n");
34 }
35 }