TP11 exo2: Add basics UI functions and integrate them is the static and
[TD_C.git] / TP_11 / exo2 / ui.c
diff --git a/TP_11/exo2/ui.c b/TP_11/exo2/ui.c
new file mode 100644 (file)
index 0000000..998b846
--- /dev/null
@@ -0,0 +1,29 @@
+#include <stdio.h>
+
+#include "ui.h"
+
+int promptValue(const char* msg, int* result) { 
+    puts(msg); 
+    int retVal = scanf("%d", result); 
+    return (retVal == 1) ? 0 : 1; 
+}
+
+void displayArray(const int array[], unsigned length) {
+    printf("--Begin--\n");
+    for (unsigned i = 0; i < length; i++) {
+        printf("array[%d]=%d\n", i, array[i]);
+    }
+    printf("--End--\n");
+}
+
+void displayList(link_t* head) {
+    unsigned i = 0;
+
+    printf("--Begin--\n");
+    while (head != NULL) {
+        printf("value at [%d]=%d\n", i, head->value);
+        head = head->next;
+        i++;
+    }
+    printf("--End--\n");
+}