From 731a470e947f3c7fcd9012cd7982cf2488f57381 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Mon, 27 Feb 2017 19:48:35 +0100 Subject: [PATCH] Add TP8 exo2 MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- TP_8/exo2/Makefile | 31 +++++++++++++++++++++++++++++++ TP_8/exo2/exo2.c | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+) create mode 100644 TP_8/exo2/Makefile create mode 100644 TP_8/exo2/exo2.c diff --git a/TP_8/exo2/Makefile b/TP_8/exo2/Makefile new file mode 100644 index 0000000..184cdd5 --- /dev/null +++ b/TP_8/exo2/Makefile @@ -0,0 +1,31 @@ +TARGET = exo2 +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/exo2/exo2.c b/TP_8/exo2/exo2.c new file mode 100644 index 0000000..ba0dfd2 --- /dev/null +++ b/TP_8/exo2/exo2.c @@ -0,0 +1,38 @@ +#include +#include + +/** Display a prompt to the user then wait for an integer input. */ +int promptValue(const char* prompt) { + printf("%s:\n", prompt); + int result; + scanf("%d", &result); + return result; +} + +/** Linked list of int */ +typedef struct link_s { + int value; + struct link_s* next; +} link_t; + +link_t* list_new(int value) { + link_t* link_t_new; + link_t_new = malloc(sizeof(link_t)); + link_t_new->value = value; + link_t_new->next = NULL; + return link_t_new; +} + +void list_clear(link_t* link) { + free(link); +} + +int main() { + link_t* head; + int value = promptValue("Entrer l'entier a mettre dans un maillon"); + head = list_new(value); + printf("Valeur entiere dans le maillon: %d\n", head->value); + list_clear(head); + + return 0; +} -- 2.34.1