<span style= "FONT-FAMILY:KAITI_GB2312;FONT-SIZE:18PX;" > #include <stdio.h> #include <stdlib.h>/* provide malloc () prototype */#include <string.h> Provides strcpy prototype # tsize 45struct film{Char title[tsize]; int rating; struct film * NEXT; The next structure pointing to the list};int main (void) {struct film * head = NULL; struct film * prev, * current; Char input[tsize];//collects and stores information puts ("Enter first movie title:"); while (gets (input) = NULL && input[0]! = ' + ') {current = (struct film *) malloc (sizeof (struct film)); if (head = = NULL) head = current; else Prev->next = current; strcpy (Current->title,input); Puts ("Enter your Rating<0-10>:"); scanf ("%d", ¤t->rating); while (GetChar ()! = ' \ n ') continue; Puts ("Enter next movie title (empty line to stop):"); prev = current; } if (head = = NULL) {printf ("No Data entered!"); } ElSe printf ("Here is the movie list:\n"); current = head; while (current = NULL) {printf ("Movie:%s Rating:%d\n", current->title,current->rating); Current = current->next; } printf ("bye!! \ n "); return 0;} </span>
<span style= "FONT-FAMILY:KAITI_GB2312;FONT-SIZE:18PX;" ></span>
There are three steps to creating a linked list:
1. Use the malloc () function to allocate enough space for a structure
2. Store the address of this structure
3. Copy the correct information into this structure
Create a linked list instance