Im having trouble writing a linked list that and a simple summation of the nodes....
Code:
#include <stdio.h>
typedef struct Node {
int val;
struct Node *next;
} *list_pointer;
/* sum_list - Sum the elements of a linked list */
int sum_list(list_pointer ls)
{
int val = 0;
while (ls) {
val += ls->val;
ls = ls->next;
}
return val;
}
int main()
{
list_pointer *head;
Node a;
Node b;
Node c;
Node d;
a.val = 1;
b.val = 3;
c.val = 5;
d.val = 9;
a.next = &b;
b.next = &c;
c.next = &d;
printf( " %d \n", sum_list(head);
}
Im sortof new to C, can anyone help me debug this.....