Add TP8 exo2
[TD_C.git] / TP_8 / exo2 / exo2.c
CommitLineData
731a470e
JB
1#include <stdio.h>
2#include <stdlib.h>
3
4/** Display a prompt to the user then wait for an integer input. */
5int promptValue(const char* prompt) {
6 printf("%s:\n", prompt);
7 int result;
8 scanf("%d", &result);
9 return result;
10}
11
12/** Linked list of int */
13typedef struct link_s {
14 int value;
15 struct link_s* next;
16} link_t;
17
18link_t* list_new(int value) {
19 link_t* link_t_new;
20 link_t_new = malloc(sizeof(link_t));
21 link_t_new->value = value;
22 link_t_new->next = NULL;
23 return link_t_new;
24}
25
26void list_clear(link_t* link) {
27 free(link);
28}
29
30int main() {
31 link_t* head;
32 int value = promptValue("Entrer l'entier a mettre dans un maillon");
33 head = list_new(value);
34 printf("Valeur entiere dans le maillon: %d\n", head->value);
35 list_clear(head);
36
37 return 0;
38}