Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Filename problems 1

Status
Not open for further replies.

deepsheep

Programmer
Sep 13, 2002
154
CA
I think I'm having a problem with file names, but I'm not too sure. I have a config file that specifies the file name of a logo and some other data. The other data seems to come out ok, but my program is unable to read the logo file. I've verified that what my file name variable contains is really what the config file contains.

In the config file I've tried it this way:
B:\\TEST.JPG
and this way:
B:\TEST.JPG
and I think even this way:
B://TEST.JPG
It fails trying to open the file. I try to open it like this:
if( (dataFile = fopen(LOGOFILENAME, "r")) == NULL ){
//fails here
return
}

If I don't use the value and just hard-code the name it works. The format I use is this:
if( (dataFile = fopen("B:\\TEST.JPG", "r")) == NULL ){
}
//continues processing

I think it has to do with the format I put into the config file for the logo name & path, but I've tried everything my brain has. Any Ideas?
Thanks!
 
char LOGOFILENAME[20];

and I fill it like this:
if(fgets(formFileBuf, 299, f_input) != NULL)//logo filename
strcpy(LOGOFILENAME, formFileBuf);

The filename I put in the config file is the same one I get out of my LOGOFILENAME variable.

If it helps, I'm using ROM-DOS as a platform.
 
printf the value of LOGOFILENAME after your gets() to see what it looks like.
 
Since you're reading it in and not defining it as a literal string, I would think a single slash or back-slash would be correct.

But, like cpjust says, print it out after reading it and tell us what you've got.
 
> if(fgets(formFileBuf, 299, f_input) != NULL)
You need to remove the \n from the end of the line returned by fgets() before you try and open the file.

Otherwise, you're doing the equivalent of
fopen("B:\\TEST.JPG\n"

--
 
Your post about the \n put me on the right track!

I tried:
LOGOFILENAME[length-3]=0;
but that cut off the last two characters so I did:
LOGOFILENAME[length-1]=0;
and it worked!

I used this format in the file: B:\TEST.JPG

Many thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top