Below is a small portion of the source code where fclose
is causing error? This function is not called always, at some particular condition this function is called.
int write_into_file (char * file_name)
{
FILE * fp = NULL ;
if (file_name == NULL)
{
return FAIL ;
}
if ((fp = fopen (file_name , "r")) == NULL)
{
if ((fp = fopen (file_name, "w")) == NULL)
{
return FAIL ;
}
}
fclose (fp) ;
fp = NULL ;
return SUCESS;
}
We are passing character buffer of size 1024 to file_name. Please can anyone tell me why fclose causes segmentation fault?