struct patient { char firstname[20]; char lastname[20]; int age; int id; struct
ID: 3613087 • Letter: S
Question
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)); //c compileerror so pls help
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);
}
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)); //c compileerror so pls help
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);
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.