-
Can't FOPEN in Turbo C?
I have installed turbo c into C:\TC, and created a Work folder in that, so I have C:\TC\Work\test.c
In test.c, a portion of it is:
Code:
FILE *file;
file = fopen("maze.txt", "rb");
if (file == NULL) {
printf("Error: Could not open file");
}
I get a could not open file, but maze.txt is in C:\TC\Work... I've also tried just putting it into C:\TC, yet it still does not seem to work. I've also tried Going Alt+O->Directories->Setting to C:\TC\Work.
Any help is VERY MUCH appreciated!
-
Reply
Is that where the exe is compiled? try putting it in the debug folder (if it has one), I only have experience with using VC++ as an IDE
Chris
-
Code:
FILE *file;
file = fopen("c:\\tc\\maze.txt", "rb");
if (file == NULL) {
printf("Error: Could not open file");
}
You have to explicitly specify the path, if the code runs in a different path. Always having a path specifier as part of the filename is the best approach. That way you can be sure of which file you are opening. It's not uncommon for files in other paths to have identical names.