TP 11 exo2: Reorganize the directories structure to make use of the
[TD_C.git] / TP_11 / exo2 / src / main.c
diff --git a/TP_11/exo2/src/main.c b/TP_11/exo2/src/main.c
new file mode 100644 (file)
index 0000000..65e791b
--- /dev/null
@@ -0,0 +1,34 @@
+#include <stdlib.h>
+#include <stdio.h>
+#include <stdbool.h>
+
+#include "ui.h"
+
+int main() {
+    link_t* head = NULL;
+    unsigned counter = 0;
+    int value = 0;
+    int promptrtVal = 0;
+    int* array = NULL;
+
+    while (true) {
+       promptrtVal = promptValue("Saisir une valeur:", &value);
+       if (promptrtVal != 0)
+           break;
+       head = list_append(head, value);
+       counter++;
+    }
+    printf("Liste:\n");
+    displayList(head);
+    array = malloc(counter*sizeof(int));
+    array[0] = list_get(head, 0);
+    for (unsigned i = 1; i < counter; i++) {
+        array[i] = array[i-1] + list_get(head, i);
+    }
+    printf("Tableau des sommes:\n");
+    displayArray(array, counter);
+    list_clear(head);
+    free(array);
+
+    return 0;
+}