c - fgets () segmentation fault -


i have simple code in c read file 1 line , print till exist line when want run on linux mint segmentation fault code is:

# include <stdio.h> int main(){     file * fr;     fr = fopen ("t.txt", "rt");     char line[100];      while(fgets(line, 100, fr) != null)    {         printf("%s",line);     }    fclose(fr); } 

and gdb says: program received signal sigsegv, segmentation fault. 0xb7e82b07 in fgets () /lib/i386-linux-gnu/libc.so.6 (gdb)

but can't find problem, can 1 me?

fr = fopen ("t.txt", "rt"); 

from did idea of using "rt"? that's not valid option fo fopen(), it's returning null... rest imagination.


moral: do error checking.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -