| | |
fgets crash issues
Please support our C advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Apr 2006
Posts: 14
Reputation:
Solved Threads: 0
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.
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.
Thanks
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.
C Syntax (Toggle Plain Text) - 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.
Thanks
•
•
Join Date: Apr 2006
Posts: 14
Reputation:
Solved Threads: 0
Well, nevermind, I feel stupid now... It seems I had a "file leak" somewhere else in my program that opened a file and never closed it, so I attained the maximum number of files open.
I had to test it on a Linux system, though, to give me the errno. Any reason why on Windows the program doesn't return an error value when it can't open a file?
I had to test it on a Linux system, though, to give me the errno. Any reason why on Windows the program doesn't return an error value when it can't open a file?
![]() |
Similar Threads
- Right-click crash from icons (Windows NT / 2000 / XP)
- Scanf vs fgets (C)
- Computer freezes badly while gaming, help plz! (Troubleshooting Dead Machines)
- Computer repeatedly crashing (Windows NT / 2000 / XP)
- home work help funcations and arry issues (C)
- Control panel issues; slow startup (Viruses, Spyware and other Nasties)
- Should I buy Apple or PC? (IT Professionals' Lounge)
- ASP.NET and Mozilla - Issues! (ASP.NET)
- win XP issues (Windows NT / 2000 / XP)
- Graphics Card issues Stop Command??? (Windows NT / 2000 / XP)
Other Threads in the C Forum
- Previous Thread: Read from a file then placing strings into a 2d array
- Next Thread: WIN32 ListView Control Column Click
| Thread Tools | Search this Thread |
adobe ansi api array arrays asterisks binarysearch calculate centimeter char convert copyimagefile copypdffile cprogramme creafecopyofanytypeoffileinc createcopyoffile csyntax directory dynamic fflush file fork forloop frequency getlasterror givemetehcodez graphics gtkgcurlcompiling hacking hardware highest homework i/o inches incrementoperators infiniteloop initialization interest kernel km linked linkedlist linux linuxsegmentationfault list lists locate logical_drives match matrix microsoft motherboard multi mysql number open opendocumentformat opensource owf pattern pdf performance pointer pointers posix power problem probleminc program programming pyramidusingturboccodes radix read recursion recv repetition research scanf scheduling scripting segmentationfault send sequential shape socketprograming stack standard string strings structures systemcall testautomation turboc unix user variable voidmain() wab win32api windows.h






