Code:
int main()
{
FILE *file;
file = fopen("C:/Users/dell/Desktop/File/init.txt","r");
int xcount;
char c[4],brown_spec[2],brown_conc[1];
float *x=NULL;
float ***brown;
int line_read=0,xtime=0,xconc_range=0,xspecies=0,i=0,j=0;
if (file!=NULL)
{
while(line_read<3 && fgets(c,10,file)!=NULL )
{
line_read++;
if (line_read==1)
{
xtime=atoi(c);
}
if (line_read==2)
{
xconc_range=atoi(c);
}
if (line_read==3)
{
xspecies=atoi(c);
}
}
brown=(float***)malloc(xspecies*sizeof *brown);
for( i=0; i<xspecies ; i++ )
{
brown[ i ] =(float**)malloc(xtime* sizeof **brown);/* Allocate 'xtime' number of pointers to int */
/*Validate malloc's success/failure using the return value*/
for( j=0; j<xtime; j++)
{
brown[ i ][ j ]= (float*)malloc(xconc_range* sizeof ***brown);/* Allocate 'xconc_range' number of ints */
/*Validate malloc's success/failure using the return value*/
}
}
while(fgets(c,10,file)!=NULL && line_read>=3)
{
strncpy(brown_spec,&c[2],1);
if(brown_spec[0]=='=')
{
strncpy(brown_spec,&c[1],1);
strncpy(brown_conc,&c[3],1);
}
else
{
strncpy(brown_spec,&c[1],2);
strncpy(brown_conc,&c[4],1);
}
brown[atoi(brown_spec)][0][atoi(brown_conc)]=1;
line_read++;
}
}
exit(0);
return 0;
}
Hi The problem with the above code is that if i dont put the exit function before return it gives an error , but when i put the exit function it works fine... can u tell me why such is the case?
Tnks