Results 1 to 3 of 3

Thread: Can't FOPEN in Turbo C?

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2002
    Posts
    259

    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!
    SonicMailer Pro
    The best mailing list manager has just gotten better!
    Click here for a full list of features!

  2. #2
    Junior Member
    Join Date
    Nov 2002
    Location
    Left past the postbox
    Posts
    30

    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

  3. #3
    Frenzied Member
    Join Date
    Jul 2002
    Posts
    1,370
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width