From: Jérôme Benoit Date: Mon, 27 Feb 2017 15:04:56 +0000 (+0100) Subject: TP_8 exo1 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=e1b5a0c2efdaae55cb7ccb02126766c41b33afa4;p=TD_C.git TP_8 exo1 Signed-off-by: Jérôme Benoit --- diff --git a/TP_8/exo1/Makefile b/TP_8/exo1/Makefile new file mode 100644 index 0000000..b24c120 --- /dev/null +++ b/TP_8/exo1/Makefile @@ -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 index 0000000..b10155c --- /dev/null +++ b/TP_8/exo1/exo1.c @@ -0,0 +1,30 @@ +#include +#include + +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; +}