Mail Archives: djgpp/1997/07/31/23:04:04
Joshua Eckstein wrote:
>
> I'm trying to find out how to specify a filename as not to be
> drive/directory specific. In other words, if someone puts the executable in
> [xfolder] and I have established a branch directory for data, it will look
> in [xfolder]\data. Like so:
>
> LoadPic ("\data\example.pic", ...);
Omit the beginning slash. This makes the path relative to the current
working directory. If you're looking for a data file that will always
be in a subdirectory of your program's installation directory, then you
can find the correct drive/directory by examining argv[0], which should
contain the full pathname of the executable.
Example:
#include <stdio.h>
#include <dir.h>
int main( int argc, char *argv[] )
{
char progdir[FILENAME_MAX], filename[FILENAME_MAX];
char drive[MAXDRIVE], dir[MAXDIR], name[MAXFILE], ext[MAXEXT];
fnsplit( argv[0], drive, dir, name, ext );
sprintf( progdir, "%s%s", drive, dir );
/* ... */
sprintf( filename, "%s%s", progdir, "example.pic" );
LoadPic( filename, /* ... */ );
/* ... */
return 0;
}
--
---------------------------------------------------------------------
| John M. Aldrich, aka Fighteer I | mailto:fighteer AT cs DOT com |
| Proud owner of what might one | http://www.cs.com/fighteer |
| day be a spectacular MUD... | Plan: To make Bill Gates suffer |
---------------------------------------------------------------------
- Raw text -