Try the "comp.lang.c.moderated" group for C and C library questions.
You probably meant:
if( fp != NULL )
fclose( fp );
That is, "!= NULL" rather than "== NULL".
On 20 March 2011 22:47, bd satish wrote:
> Hi,
>
> I'm trying to close a file using fclose, but the following program seg-faults:
>
>
> #include
>
> int main(void)
> {
> FILE* fp = fopen("unfounded.txt", "r");
>
> if(fp == NULL)
> fclose(fp);
>
> return 0;
> }
>
>
> The file I'm tr
Hi,
I'm trying to close a file using fclose, but the following program seg-faults:
#include
int main(void)
{
FILE* fp = fopen("unfounded.txt", "r");
if(fp == NULL)
fclose(fp);
return 0;
}
The file I'm trying to open doesn't exist in the directory, so fp is
indeed NULL.