From: Jérôme Benoit Date: Wed, 1 Mar 2017 07:59:51 +0000 (+0100) Subject: TP 9 exo2: Simplify the return value handling in the list counting X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=490c6927e0a997c48a9c21649491272b777b70d3;p=TD_C.git TP 9 exo2: Simplify the return value handling in the list counting function. Signed-off-by: Jérôme Benoit --- diff --git a/TP_9/exo2/clist.c b/TP_9/exo2/clist.c index db08117..2857042 100644 --- a/TP_9/exo2/clist.c +++ b/TP_9/exo2/clist.c @@ -32,9 +32,10 @@ link_t* list_prepend(link_t* head, int value) { } unsigned list_count(link_t* head) { - int count = 1; + int count = 0; - if (head == NULL) { return 0; } + if (head == NULL) { return count; } + count = 1; while (head->next != NULL) { ++count; head = head->next;