Question: Modify the program so that it adds each new node at the end of the list. #include #include #include struct Node { char *data; struct

Modify the program so that it adds each new node at the end of the list.

#include #include #include struct Node { char *data; struct Node *next; }; int main(int argc, char ** argv) { FILE *infile; char buf[200]; infile = fopen(argv[1], "r"); // get input file from command line struct Node *p, *head = NULL;

while (fgets(buf, sizeof(buf), infile)) // create list { p = (struct Node *)malloc(sizeof(struct Node)); p->data = strdup(buf); p-> next = head; head = p; }

p = head; // traverse list while (p) { printf("%s", p->data); p = p->next; } }

xt; } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!