Re: segmentation fault with fclose

2011-03-22 Thread Jeremy Hall
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".

Re: segmentation fault with fclose

2011-03-20 Thread Jonathan Wakely
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

segmentation fault with fclose

2011-03-20 Thread bd satish
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.