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

This is c language and I have a file which I want to read it tothis array of poi

ID: 3612795 • Letter: T

Question

This is c language and I have a file which I want to read it tothis array of pointers to structure. I have 2 doctors and 3patients, and the clinic I want to read and store it to thestructure objects, so this is how it is:
#include<stdio.h>
struct doctors
{
       char firstname[20];
        char lastname[20];
        int operationid;
};
struct patients
{
        char firstname[20];
        char lastname[20];
    int chosendocid;
};
struct clinic
{
char clinicname[25];
      struct doctors *ptr[2];  //an array of pointers to objects of the doctor structure
      struct patients *pat[3]   //an array of pointers to objects of the patient structure
                                          //I can only use this array of pointers.
};
void recursivealloc_mem(FILE *notefile, struct patients, intrec);
int main(void)
{
        FILE *notefile;
        struct clinichosp;   //I can only declare this two localvaluables,
      

        int rec=2;

         notefile =fopen("file1.dat", "r");
        if(notefile == NULL)
        {
               printf("file1.dat file does not exist ");
               return(-1);
        }
            recursivealloc_mem( notefile, &hosp, rec);
        fclose(notefile);
}

void recursiveallocdoc_mem(FILE *notefile, struct clinic *xhosp,int rec)
{
        int index, xindex =1;
        //if(xindex <=rec)
              // recursiveallocdoc_mem(rec -1);      

       For(index=0;index<2;index++)                                 //MYONLY PROBLEM IS HOW I CAN REPLACE THIS LOOP TO RECURSIVE
               xhosp->doc[index] = malloc(1 * sizeof( struct doctor));
      for(index=0;index<2;index++)
       {
          fscanf(notefile, "%s %s %d ",xhosp->doc[i]->firstname,xhosp->doc[i]->lastname,    xhosp->doc[i]->id);

      printf("%s, %s,%d ",xhosp->doc[i]->firstname,xhosp->doc[i]->lastname, xhosp->doc[i]->id);
}
}



}
And the file I have written so far is:
James
Warren
3542
Maud
Spearman
2267
Ike
Williams
2267
Caleb
Walker
3542

I am trying to let the program read and store it by allocatingmemory recursively, that's the one it's giving me problems. PleaseI can only declare the structure objects like it is. So please howcan I recursively allocate memory for it?

Explanation / Answer

#include#includestruct doctors{char firstname[20];char lastname[20];int operationid;};struct patients{char firstname[20];char lastname[20];int chosendocid;};struct clinic{char clinicname[25];struct doctors *doc[2]; //an array of pointers to objects of the doctor structurestruct patients *pat[3]; //an array of pointers to objects of the patient structure//I can only use this array of pointers.};void recursiveallocdoc_mem(FILE *notefile, struct clinic *, int rec); int main(void){FILE *notefile;struct clinic hosp; //I can only declare this two local valuables,int rec=2;notefile = fopen("file1.dat", "r");if(notefile == NULL){printf("file1.dat file does not exist ");return(-1);}recursiveallocdoc_mem( notefile, &hosp, rec);fclose(notefile);}void recursiveallocdoc_mem(FILE *notefile, struct clinic *xhosp, int rec){int index, xindex ,i;//if(xindex firstname, xhosp->doc[i]->lastname, &(xhosp->doc[i]->operationid));printf("%s, %s, %d ",xhosp->doc[i]->firstname, xhosp->doc[i]->lastname, xhosp->doc[i]->operationid);}}
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