Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

i have error in atexit(report_mem_leak); how to solve it ? #include #include #include #include #includeleak-detector-c.h typedef struct monster { int id; char *name; char *element;

i have error in atexit(report_mem_leak); how to solve it ?

#include #include #include #include #include"leak-detector-c.h" typedef struct monster { int id; char *name; char *element; int population; } monster; typedef struct region { char *name; int nmonsters; int total_population; monster **monsters; monster*m; } region; typedef struct itinerary { int nregions; region **regions; region *r; int captures; } itinerary; typedef struct trainer { char *name; itinerary *visits; } trainer;

int main(void){ //for creating the file that contains the information about the memory leak atexit(report_mem_leak); //file to take input from FILE *fptr; fptr = fopen("in.txt","r"); monster *mstruct; int nmonster,nregion,ntrainer,i,j,k; char vmonster[24],vregion[24],vtrainer[24],string[50]; fscanf(fptr,"%d",&nmonster); fscanf(fptr,"%s",vmonster); mstruct = (monster *)malloc( sizeof(monster) * nmonster); for(i=0;icaptures); fscanf(fptr,"%s",string); fscanf(fptr,"%d",&tstruct[i].visits->nregions); fscanf(fptr,"%s",string); tstruct[i].visits->r = (region *)malloc( sizeof(region) *tstruct[i].visits->nregions); for(j=0;jnregions;j++){ tstruct[i].visits->r[j].name= (char *)malloc( sizeof(char) * 24 ); fscanf(fptr,"%s",tstruct[i].visits->r[j].name);}} int total,l,m,z; float a,p,q,r; char *c,*d; FILE *ptr;ptr = fopen("outFile.txt","w"); for(i=0;inregions;j++){ fprintf(ptr,"%s ",tstruct[i].visits->r[j].name); for(k=0;kr[j].name; d=rstruct[k].name; if(strcmp(c,d)==0){ total=0; for(l=0;lcaptures; r=(a/q);r=r*p;r=round(r); z=r; if(z==0) continue; fprintf(ptr,"%d %s ",z,mstruct[m].name);}}}}}}} free(mstruct); for(i=0;ir ); for(j=0;jnregions;j++){ free(tstruct[i].visits->r[j].name); }} return 0; }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Temporal Databases Research And Practice Lncs 1399

Authors: Opher Etzion ,Sushil Jajodia ,Suryanarayana Sripada

1st Edition

3540645195, 978-3540645191

More Books

Students also viewed these Databases questions

Question

Describe criteria for choosing communication media.

Answered: 1 week ago

Question

Identify three types of physicians and their roles in health care.

Answered: 1 week ago

Question

Compare the types of managed care organizations (MCOs).

Answered: 1 week ago