Jump to content
  • Advertisement
Sign in to follow this  
MaxDemian

File open error

This topic is 3660 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

Hi, I found a code that open a file with this string: "C:\file.jpg/info"
bool aeSpriteBase::Init(char * dir)
{
	char buffer[255];
	char filename[255];
	char name[255];
	FILE * fp;

	sprintf(filename,"%s/info",dir);

	if( (fp = fopen(filename,"r")) == NULL )
	{
		fprintf(stderr,"Error opening file: %s\n",filename);
		return false;
	}
...
}

I got an error when I try to open the file. I think the "/info" string is the problem, but the code I've read use that. Can anyone explain me what is it for and why I'm having problems? Thanks

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by MaxDemian
Hi, I found a code that open a file with this string: "C:\file.jpg/info"

*** Source Snippet Removed ***
I got an error when I try to open the file. I think the "/info" string is the problem, but the code I've read use that.

Can anyone explain me what is it for and why I'm having problems?

Thanks


umm... it's looking for a file info in C:\file.jpg\ and not finding it, I assume. Remove the /info.

Share this post


Link to post
Share on other sites
you could have debugged this by printing the exact file location it was looking for. then you could have seen what the problem was. Consider outputting your data in this way next time, especially if its a large calculation (output the results of intermediate calculations) or building a string from substrings.

Share this post


Link to post
Share on other sites
I found that dir must be a directory and /info is to get the information of the directory: Num of files, etc...

but still having errors

Share this post


Link to post
Share on other sites
It's expecting there to actually be a file called "info" in the directory. You can have files without extensions, and this appears to be what it's looking for. If the file doesn't exist, you'll get an error with mode "r".

It's not some magical property of the file system that's going to give you info out of thin air.

Share this post


Link to post
Share on other sites
Quote:
Original post by Nypyren
It's expecting there to actually be a file called "info" in the directory. You can have files without extensions, and this appears to be what it's looking for. If the file doesn't exist, you'll get an error with mode "r".

It's not some magical property of the file system that's going to give you info out of thin air.


So info is a file isnt it? then why "/info" and not "\info"?

PS: I've get code from here(page 3): http://cone3d.gamedev.net/pdfs/GFXwithSDLPart3.pdf

Share this post


Link to post
Share on other sites
Quote:
Original post by MaxDemian
PS: I've get code from here(page 3): http://cone3d.gamedev.net/pdfs/GFXwithSDLPart3.pdf
The code in that article loads a file named 'info', which has been filled out by the author to contain settings/whatever.

Share this post


Link to post
Share on other sites
Quote:
Original post by swiftcoder
Quote:
Original post by MaxDemian
PS: I've get code from here(page 3): http://cone3d.gamedev.net/pdfs/GFXwithSDLPart3.pdf
The code in that article loads a file named 'info', which has been filled out by the author to contain settings/whatever.


OK, but why "/" and not "\" ?

Share this post


Link to post
Share on other sites
Quote:
Original post by MaxDemian
Quote:
Original post by swiftcoder
Quote:
Original post by MaxDemian
PS: I've get code from here(page 3): http://cone3d.gamedev.net/pdfs/GFXwithSDLPart3.pdf
The code in that article loads a file named 'info', which has been filled out by the author to contain settings/whatever.
OK, but why "/" and not "\" ?
Presumably because the author was more familiar with unix/linux/mac, where '/' is the path separator. On Windows you will want to use '\' instead - but note carefully that in 'C:\file.jpeg\info', the character sequences '\f' and '\i' are escape codes, so you must escape the backslashes: 'C:\\file.jpeg\\info'.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • 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!