list.h ====== #define NULL 0 /* linear list header file */ typedef char DATA; /* will use char in examples */ struct linked_list { DATA d; struct linked_list *next; }; list.c ====== typedef struct linked_list ELEMENT; typedef ELEMENT *LINK; #include #include #include "list.h" LINK string_to_list(char []); void print_list(LINK); int count(LINK); main() { LINK h; h = string_to_list("ABC"); printf("The resulting list is\n"); print_list(h); printf("\nThis list has %d elements.\n", count(h)); } Output ====== The resulting list is A --> B --> C --> NULL This list has 3 elements. LINK string_to_list(char s[]) { LINK head; if (s[0] == '\0') /* base case */ return NULL; else { head = malloc(sizeof(ELEMENT)); head -> d = s[0]; head -> next = string_to_list(s + 1); return head; } } void print_list(LINK head) { if (head == NULL) printf("NULL"); else { printf("%c --> ", head -> d); print_list(head -> next); } } int count(LINK head) { if (head == NULL) return 0; else return (1 + count(head -> next)); }