Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please my problem is stated below, and below is the text file andthe driver file

ID: 3613080 • Letter: P

Question

Please my problem is stated below, and below is the text file andthe driver file. Thanks

Pete 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 *nextnode;    
};
void pat(FILE *xfiles, struct clinic *mems);
int main(void)
{
          FILE*file;
         struct clinicmembers;
struct patient *xpter       

       file = fopen("textfile","r");
       if(file == NULL)
        {
           printf("textfile unavailable ");
            exit(0);
         }

       pat(file, &members);
       storeobject(xpter,&members);
       fclose(file);
}
void pat(FILE *xfiles, struct clinic *mems)
{
        struct patient*pter;
        mems->nextnode =(struct patient *) malloc(1 * sizeof(struct patient);
        
      while(fscanf(xfiles, "%s %s %d %d",members->nextnode->firstname,             members->nextnode->lastname,&(members->nextnode->age),  &(members->nextnode->id)) != EOF);
  
}
void storeobject(struct patient *xpat, struct clinic *mems)
{
    struct patient*firstpatient;
           struct patient *secondpatient;

           firstpatient = mems;
           secondpatient = mems;
       
            printf(" First name: %s Last Name: %s Age: %d IdNumber: %d ", firstpatient->firstname,firstpatient->lastname, firstpatient->age,firstpatient->id);

            printf(" First name: %s Last Name: %s Age: %d IdNumber: %d ", secondpatient->firstname,secondpatient->lastname, secondpatient->age,secondpatient->id);

}

PLEASE I WANT TO COPY EACH PATIENT TO EACH STRUCTURE POINTERS BUTEVERY TIME I EXECUTE IT, IT EACH POINTER PRINTS THE WHOLE PATIENTSTEXT FILE AND THAT'S SOMETHING I DON'T WANT, I KNOW THE WHILE LOOPGOT SOMETHING TO DO WITH IT BUT IF I TAKE IT OUT THE FILE POINTERCAN'T INCREMENT, SO PLEASE WHAT WHAT CAN I DO?









       
}
     


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

struct patient
{
       char firstname[20];
       char lastname[20];
       int age;
       int id;
       struct patient *link;
};
struct clinic
{
     char nameofclinic[30];
     struct patient*nextnode;     
};
void pat(FILE *xfiles, struct clinic *mems);
void storeobject(struct patient *xpat, struct clinic *mems);
int main(void)
{
          FILE*file;
         struct clinicmembers;
          structpatient *xpter ;      

       file = fopen("textfile","r");
       if(file == NULL)
        {
           printf("textfile unavailable ");
            exit(0);
         }

       pat(file,&members);
       storeobject(xpter,&members);
       fclose(file);
       system("pause");
}
void pat(FILE *xfiles, struct clinic *mems)
{
        struct patient*ptr,*members;
      
        members= (struct patient*) malloc(1 * sizeof(struct patient));
        ptr = mems ->nextnode= (struct patient *) malloc(1 * sizeof(structpatient));
        ptr->link=NULL;
      while(fscanf(xfiles, "%s %s %d %d",members->firstname,             members->lastname, &(members->age),  &(members->id)) != EOF)
      {

       
        memcpy(ptr,members,sizeof(struct patient));
        ptr->link = (structpatient *) malloc(1 * sizeof(structpatient));     
        ptr=ptr->link;
        ptr->link =NULL;
      }
    
}
void storeobject(struct patient *xpat, struct clinic *mems)
{
           struct patient *firstpatient;
           struct patient *secondpatient;

           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);

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote