File open error

Started by
7 comments, last by swiftcoder 15 years, 5 months ago
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
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.
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.
Don't thank me, thank the moon's gravitation pull! Post in My Journal and help me to not procrastinate!
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
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.
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
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.

Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]

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 "\" ?
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'.

Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]

This topic is closed to new replies.

Advertisement