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
2010-06-24 23:05:57
or just under gdb and do a bt when it segfaults
ninjalj
2010-06-24 23:58:07
@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
2010-06-25 00:22:34
valgrind rules! +!
Norman Ramsey
2010-06-25 01:33:21