Hello, I am running a heuristic search algorithm (running on Windows XP), and at each iteration, I want to write results in an output file. The issue that I have is that after a number of iteration, my program crashes at the line where I have the "fputs(str, f);" (See below). It crashes right after it calls the fputs, so I can't even use the returned value of the call for error checking, since it doesn't even seem to get far enough to return a value.
It seems to be dependent on the amount of data that I am writing in the output file. Since I have multiple test problems that I can run my algorithm on, I can test it on several different problems. While the numbers are not constant, the program is usually able to write roughly 120 lines, or 5400 characters, no matter the test problem that I use.
Here is the portion of the code where I write the data onto the file.
FILE * f = fopen("Output.txt", "a"); sprintf(str, "%lf,%lf,%d,%d,%lf,%lf\n\0", var1, var2, var3, var4, var5, var6) fputs(str, f); fclose(f);
Also, the resulting string 'str' has no problematic values, because I can put the line "printf("%s", str);" before the fputs() line, and it will show the value of the string properly.
Since I don't even have a clue as to why a fgets() call crashes my problem, I am turning to you guys, hoping you know what can cause this.
Edited 4 Years Ago by Dani: Fixed formatting