views:

106

answers:

1

I am writing a C program that reads a text file and parses the data in it into various fields. The text file I am reading from is very large though (31MB) and when I run the program on a text file that has 41880 lines of input everything works fine. I will ultimately need to read from text files that are much much larger than that though. So when I increase the lines to 41881 though I get a segmentation fault. Any ideas?

+2  A: 

You are trashing memory somewhere along the way and it's finally hitting you at line 41881.

If your platform is supported, try running under Valgrind.

R Samuel Klatchko
or just under gdb and do a bt when it segfaults
ninjalj
@ninjalj - that is a very different thing. gdb will show you your context at the moment the crash setfault occurs. But if the code that trashes memory does not immediately trigger a crash (which is unfortunately quite common), knowing where the crash occurred may not help you find where the actual bug is.
R Samuel Klatchko
valgrind rules! +!
Norman Ramsey