TP 9 exo2: Simplify the return value handling in the list counting
authorJérôme Benoit <jerome.benoit@piment-noir.org>
Wed, 1 Mar 2017 07:59:51 +0000 (08:59 +0100)
committerJérôme Benoit <jerome.benoit@piment-noir.org>
Wed, 1 Mar 2017 07:59:51 +0000 (08:59 +0100)
function.

Signed-off-by: Jérôme Benoit <jerome.benoit@piment-noir.org>
TP_9/exo2/clist.c

index db081179bae025aa5d7ce1e9fd14e00d266c28e2..2857042028966a52133304c9bd73d23534b8c22b 100644 (file)
@@ -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;