4 /** Display a prompt to the user then wait for an integer input. */
5 int promptValue(const char* prompt
) {
6 printf("%s:\n", prompt
);
12 /** Linked list of int */
13 typedef struct link_s
{
18 link_t
* list_new(int value
) {
20 link_t_new
= malloc(sizeof(link_t
));
21 link_t_new
->value
= value
;
22 link_t_new
->next
= NULL
;
26 void list_append(link_t
* head
, int value
) {
28 while (head
->next
!= NULL
) {
31 head
->next
= list_new(value
);
34 unsigned list_count(link_t
* head
) {
35 // And if head is not defined?
38 while (head
->next
!= NULL
) {
45 int list_get(link_t
* head
, unsigned index
) {
47 if (index
< list_count(head
)) {
48 for (unsigned i
= 0; i
< index
; i
++) {
57 void list_clear(link_t
* link
) {
59 while (link
!= NULL
) {
60 link_t
* next_link
= link
->next
;
67 link_t
* head
= list_new(1);
68 printf("Longueur de la liste: %d\n", list_count(head
));
72 printf("Longueur de la liste: %d\n", list_count(head
));
73 printf("Valeur a index %d: %d\n", 2, list_get(head
, 2));
74 printf("Valeur a index %d: %d\n", 3, list_get(head
, 3));
75 printf("Valeur a index %d: %d\n", 4, list_get(head
, 4));