TP_8 exo1
authorJérôme Benoit <jerome.benoit@piment-noir.org>
Mon, 27 Feb 2017 15:04:56 +0000 (16:04 +0100)
committerJérôme Benoit <jerome.benoit@piment-noir.org>
Mon, 27 Feb 2017 15:04:56 +0000 (16:04 +0100)
Signed-off-by: Jérôme Benoit <jerome.benoit@piment-noir.org>
TP_8/exo1/Makefile [new file with mode: 0644]
TP_8/exo1/exo1.c [new file with mode: 0644]

diff --git a/TP_8/exo1/Makefile b/TP_8/exo1/Makefile
new file mode 100644 (file)
index 0000000..b24c120
--- /dev/null
@@ -0,0 +1,31 @@
+TARGET = exo1
+LIBS =
+CC = gcc
+# Enforce C11 ISO standard for now
+CFLAGS = -std=c11 -g -Wall
+LDFLAGS = -g -Wall
+
+.PHONY: default all clean
+
+default: $(TARGET)
+all: default
+
+OBJECTS = $(patsubst %.c, %.o, $(wildcard *.c))
+HEADERS = $(wildcard *.h)
+
+%.o: %.c $(HEADERS)
+       $(CC) $(CFLAGS) -c $< -o $@
+
+.PRECIOUS: $(TARGET) $(OBJECTS)
+
+$(TARGET): $(OBJECTS)
+       $(CC) $(OBJECTS) $(LDFLAGS) $(LIBS) -o $@
+
+clean:
+       -rm -f $(TARGET) $(OBJECTS) 
+
+disassemble: $(TARGET)
+       objdump -d $< | less
+
+symbols: $(TARGET)
+       objdump -t $< | sort | less
diff --git a/TP_8/exo1/exo1.c b/TP_8/exo1/exo1.c
new file mode 100644 (file)
index 0000000..b10155c
--- /dev/null
@@ -0,0 +1,30 @@
+#include <stdio.h>
+#include <stdlib.h>
+
+int promptValue() {
+    int value;
+    scanf("%d", &value);
+    return value;
+}
+
+int main() {
+    int* arr;
+    printf("Longeur?\n");
+    int size = promptValue();
+    arr = malloc(sizeof(arr[size]));
+    
+    for (int i = 0; i < size; i++) {
+        printf("Valeur?\n");
+        arr[i] = promptValue();            
+    }
+
+    printf("Sortie\n");
+    int sum = 0;
+    for (int i = 0; i < size; i++) {
+         printf("%d (%d)\n", arr[i], sum += arr[i]); 
+    }
+
+    free(arr);
+
+    return 0;
+}