X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=TP_8%2Fexo2%2Fexo2.c;fp=TP_8%2Fexo2%2Fexo2.c;h=ba0dfd217cc11fc18220689178c550480d6dfb1b;hb=731a470e947f3c7fcd9012cd7982cf2488f57381;hp=0000000000000000000000000000000000000000;hpb=db8e62608ddedc008ae2bba9edb7d5d03317f0a8;p=TD_C.git 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; +}