#### Archived

This topic is now archived and is closed to further replies.

# Problem with File IO

This topic is 6498 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I had this bit of code, and it worked fine
#include
#include
{
FILE *in;
if((in=fopen(loc[world],"r"))==NULL)
{
exit(1);
}
fclose(in);
}

okay, and here is my current code
#include
#include
{
FILE *in;
FILE *wlist;
if((wlist=fopen("world.txt","r"))==NULL)
{
exit(1);
}
fclose(wlist);
if((in=fopen(loc[world],"r"))==NULL)
{
exit(1);
}
fclose(in);
}

all of a sudden, my new code doesn''t work. It says the world.txt file doesn''t exist. I''M LOOKING AT IT RIGHT NOW! IT''S IN THE SAME DIRECTORY! The file contains a list of all the rooms. Without it, the next file can''t be opened. What am I doing wrong? I did something stupid while trying to figure this out. I took exit(1) out of the first attempt to open a file. DOS threw some kind of error, but I didn''t have time to read it because my computer shut down ALL ON IT''S OWN! That frickin'' pissed me off right there. shut up CAN I GET A WOO WOO!

##### Share on other sites
Try "/world.txt"

-----------------------------

A wise man once said "A person with half a clue is more dangerous than a person with or without one."

The Micro\$haft BSOD T-Shirt

##### Share on other sites
i''ve had trouble with stuff like that before, too. try putting in the *whole* file name + directory (ex: c:\stuff\world.txt). sometimes this helps.

Falden

##### Share on other sites
Actually, I figured it out. I don''t know how, but I did. It works great now. oh well.

shut up
CAN I GET A WOO WOO!

##### Share on other sites
This usually happens when you''re running a program through the compiler''s run option. when you do fopen("world.txt", "r"); it will only work if the file is actually in the same directory, which you said was the case, but if you run an app through the compiler (or even through PIF''s for DOS apps) the program isn''t being detected as if it''s being run from whatever directory its in, its being run as if the ''Working Directory'' is the local directory. The Working Dir can be anything, the compiler''s directory, the c:\ directory, even the Win9x Desktop. It used to drive me crazy too, til I figured it out.

------------
- outRider -

##### Share on other sites
Go to the project settings page if you have MSVC. Set the current working directory to your exe.

There are some commands in one of the libs to set your current working directory, but I forget what it is. I''ll make another post later stating what the name is, I''m in a hurry right now.

##### Share on other sites
I found the time...

use the funcion "chdir(const char* Path)" before you try to open any files in a win32 application.

##### Share on other sites
actually, WhatEver, I''m using BC++4.52 and doing a console app, not win32. Actaully, it''s okay, I got it to work fine. Don''t worry about it.

shut up
CAN I GET A WOO WOO!

##### Share on other sites

Just giving you info that you may find usefull in the future. It''s just that I''ve had the same snag as you, and it frustrated the hell out of me .

And I still haven''t left yet. I hate it when people say lets go before they''re ready...grrrrr.

1. 1
2. 2
3. 3
Rutin
16
4. 4
5. 5

• 10
• 14
• 30
• 13
• 11
• ### Forum Statistics

• Total Topics
631788
• Total Posts
3002356
×