Jump to content
  • Advertisement

Archived

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

Von

File I/O newbie needs help!

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

void LoadFile(char *filename); int main() { LoadFile("test.dat"); return(0); } void LoadFile(char *filename) { FILE *fp; fp = fopen(filename, "rb"); fclose(fp); } This may sounds stupid but... what''s wrong with my fopen? I have the test.dat file in the same directory as the exe file but I keep getting a NULL return by the fopen function. I tried using errno from to check out the error and discovered that "FILE IS NON-EXISTENT or FILENAME IS NULL". geez... any help would be useful.

Share this post


Link to post
Share on other sites
Advertisement
Are you using Visual C++? If so, check the "Working Directory" for your project. Another thing would to try hard coding the path in the file name.

LoadFile("c:\myapp\test.dat");

-JT

Share this post


Link to post
Share on other sites
I would guess you don''t have the file in the right directory. Try loading "C:\\test.dat" and copy your file to C:\.

Are you using MSVC++, then set the working directory in your project (Project->Settings->Debug->Working Directory). It default''s not to the Debug or Retail dir, but to your Project dir. e.g. E:\projects\myproject\debug\myproject.exe would have a working dir of E:\projects\myproject\

Share this post


Link to post
Share on other sites
It would be best to avoid C functions and use I/O stream with C++. There is a great article here on gamedev that shows how to do File I/O in ASCII and binary. Here is the URL:

http://www.gamedev.net/reference/articles/article1127.asp

If you''re male, you can only have one of two things: a conscience or a dick

Share this post


Link to post
Share on other sites
quote:
Original post by masonium
It would be best to avoid C functions and use I/O stream with C++. There is a great article here on gamedev that shows how to do File I/O in ASCII and binary.


Why would it be best? I use C i/o even in my C++ OO code, and have been for almost seven years without any problems. That wouldn''t help him solve his working directory problem anyway.

[Resist Windows XP''s Invasive Production Activation Technology!]

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
JTAnderson''s right, i think.
if you''re using Visual C++, pls remember an important thing:
VC++ running your codes in Working Directory but not in the directory your .exe''s in.
Your can modify the directory settings in the dialog Project/Settings/Debug
wish you good luck!

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!