Coin
- 564
- 1
akieft said:no the installation error is fixed. Basically the program runs, the output is ok1 and then quincy pops up an error saying that this program has quit unexpectedly and you have the option to close, debug, or send error to microsoft. If you click debug its just a bunch of numbers and I have no idea what they mean. I have a feeling it has to do with the while loop but I am unsure how to fix it.
When you see that error, it usually means you have committed a "pointer" error. That means you are trying to use a piece of memory which you think contains data, but which actually "does not exist".
The only place I see in your code where you could have committed such an error is with your FILE *input variable. It is possible, if fopen fails, that it could return NULL. Then when you say fgets(...input) later, fgets will try to read from NULL (bad) and crash.
Try adding the line
perror("fopen");
Right after you say fopen (this will cause fopen's exact error message to be printed, if there is one), or changing your printf right there to
printf("ok %x\n", input); /*if fopen succeeded, this will print a nonzero number, if it failed it will print "ok 0"*/
(If you want to be really fancy you could to an if() test to see whether "input" is equal to 0, and if input is equal to 0 print "Beatles.txt not found!" and politely quit. Your teacher would probably prefer this. But this will not solve the problem that your program doesn't work, it will just make it not work in a more polite way...)
Most compilers come with a "debugger", which when you commit a pointer error they will stop the program in its tracks and show you the source code of the line where the error happened. It is essential you learn to use a debugger someday. Does QCC not come with one?
Last edited: