Sign in to follow this  
MaxDemian

File open error

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this