#include #include #include typedef struct Node { char *name; char *address; char *phone; struct Node *next; } Node; Node* mklist(Node * list) { Node * temp; char input[3][51]; while (1) { /* read in 3 lines */ if (!fgets(input[0], 50, stdin)) break; /* if EOF, get out of the loop normally */ if (!fgets(input[1], 50, stdin)) exit(1); /* upon error, return 1 */ if (!fgets(input[2], 50, stdin)) exit(1); /* allocate memory */ temp = malloc(sizeof(Node)); temp->name = malloc(51*sizeof(char)); temp->address = malloc(51*sizeof(char)); temp->phone = malloc(51*sizeof(char)); /* copy input data in the temp node */ strcpy(temp->name, input[0]); strcpy(temp->address, input[1]); strcpy(temp->phone, input[2]); /* add the temp node to list */ temp->next = list; list = temp; } return list; } void prtlist(Node *list) { while (list) { printf("%s%s%s\n", list->name, list->address, list->phone); list = list->next; } } int main(){ Node* list = NULL; list = mklist(list); prtlist(list); return 0; }