As a part of my program, I am opening a file and reading it line by line in a loop and processing the lines.
But my program keep crashing when I try to run it..
This is the part of the code which is giving me the problem.. The loop runs exactly 14 times and then crashes. I tried putting the printf statement at different places to see where exactly it crashes. It crashes immediately after calling the fgets function.
for(j=0; j< (*anntn)[i].num_peaks; j++)
printf("Read line %d\n",j);
mz_i= (int) (mz_f +0.5);
if( (*lib_spec)[i][mz_i] < intensity)
(*lib_spec)[i][mz_i] = intensity;
printf("Finished read of line %d\n",j);
fgets(szbuf, 1500,fp); /** Skipping the blank line after the end of 1 record **/
When I googled for crashes at fgets(), most of the results talked about crashes because of trying to open a file which was opened before and wasn't closed. I only open this file once. And besides, since the first 14 lines are read correctly, I dont think the problem is because of problems with opening the file.
I thought it could be a problem with the size of szbuf.. But i increased the size 10 times and the program still crashes at the same place.
I am out of ideas. Does any one have any suggestions on what I should try..?