Please I need help on adding a node as the second node of the listand adding a n
ID: 3613068 • Letter: P
Question
Please I need help on adding a node as the second node of the listand adding a node somewhere else in the list and able to print itout. Below is my text file, I have 6 nodes in my text filePete Okay 45 345
Maud Okay 36 536
Caleb Dimitri 15 123
Cadrin Christopher 9 695
John Williams 12 542
James Evans 44 211
And below is the structure definition:
struct patient
{
char firstname[20];
char lastname[20];
int age;
int id;
struct patient *link;
};
struct clinic
{
char nameofclinic[30];
struct patient *linklist;
};
void patients(FILE *xfiles, struct patient *mems);
int main(void)
{
FILE*file;
struct clinicmembers;
struct patient *xpter
file openstatements..........
patients(file, xpter);
fclose(....);
}
void patients(FILE *xfiles, struct patient *mems)
{
struct patient*pter;
members->linklist =(struct patient *) malloc(1 * sizeof(struct patient);
pter =(struct patient *) malloc(1 * sizeof(struct patient);
fscanf(xfiles, "%s %s %d %d",members->linklist->firstname,members->linklist->lastname,&(members->linklist->age).........);
fscanf(xfiles, "%s %s %d %d",pter->firstname, pter->lastname,&(pter->age).........);
and I add a node to an empty listand add a node as the new head of the list like below
BUT I DON'T KNOW WHAT TO DO AFTER THIS SOPLEASE HELP
members->linklist->link = NULL;
pter->link =members->linklist;
members->linklist =pter;
help on adding a node as the second node of the list and adding anode somewhere else in the list and able to print it out.
Explanation / Answer
firstpatient= mems->nextnode;
secondpatient = firstpatient->link;
printf(" First name: %s Last Name: %s Age: %d IdNumber: %d ", firstpatient->firstname,firstpatient->lastname, firstpatient->age,firstpatient->id);
printf(" Second name: %s Last Name: %s Age: %d IdNumber: %d ", secondpatient->firstname,secondpatient->lastname, secondpatient->age,secondpatient->id);
}