/* File: static_linked_list.c * Purpose: Show how the linked list 5 -> 9 -> 7 should not be built. * * Compile: gcc -g -Wall -o static_linked_list static_linked_list.c * Run: ./static_linked_list * * Input: None * Output: The ints in the list * */ #include struct list_node_s { int data; struct list_node_s* next_p; }; void Print(struct list_node_s* head_p); int main(void) { struct list_node_s* head_p; struct list_node_s node1, node2, node3; node3.data = 7; node3.next_p = NULL; node2.data = 9; node2.next_p = &node3; node1.data = 5; node1.next_p = &node2; head_p = &node1; Print(head_p); return 0; } /* main */ /*----------------------------------------------------------------- * Function: Print * Purpose: Print list on a single line of stdout * Input arg: head_p */ void Print(struct list_node_s* head_p) { struct list_node_s* curr_p = head_p; printf("list = "); while (curr_p != NULL) { printf("%d ", curr_p->data); curr_p = curr_p->next_p; } printf("\n"); } /* Print */