09Aug
Segmentation faults with file pointer in C?
1 comment so farI have a program that opens a text file then adds each word to a link list going to the end of the file. The program then starts at the beginning of the file adding each word into a hash table. The problem I have is that once I have added the words to the linked list I can not rewind the file pointer. I have tried also tried fseek(fp, 0, SEEK_SET) aswell but it still causes a segmentation fault. This happens no matter where I try to rewind the file, in the create list function, create hash table function and main. The only thing that doesn’t cause a segmentation fault if ftell(fp) so I know the file pointer is still in memory.
Can any one tell me what the problem could be.
I have tried the suggestions in the first answer but it still causes a seg fault. I have also tried closing the file and opening it again with a different file pointer but it still causes a seg fault.
Categories: Programming & Design
Monday, August 9th, 2010 at 2:36 pm and is filed under Programming & Design. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.







Just a crazy thought: Try doing an fflush( fp ), or even an ftell(fp), right before the rewind( fp ). Maybe it doesn’t like the order of actions (although a seg fault is a heckuva way to handle it!)
Good luck.