Mail Archives: djgpp/1997/09/07/22:59:33
> Does anyone know how I can find out what directory a program was invoked
> from?  I would perfer an ANSI-C method, but, failing that, a
> DJGPP-specific method would be acceptable.  Specifically:
> 
> I am making a HTML editor that will look for configuration files and the
> like in the same directory as the executable.  I don't want to force the
> user to install in a particular directory, or make them add enviroment
> variables to their autoexec.bat.
> 
> thanks,
> 
> Karl Garrison
> karlos AT eznet DOT net
> 
> 
Declare main as such:
int	main( int argc, char *argv[] )
Then argv[0] is the pathname of the executable, eg
"C:/PROGRAMS/HTML/HTMLED.EXE"
Simply search backwards from the end of the string until you find a '/' and
replace it with a 0 (null), to signal the end of the string. I have a
routine that I automatically include if you would like it.
Note that the use of '/' is DJGPP specific (I think) - most other compilers
would require a '\\' (escape sequence for a backslash) as it is the DOS
standard.
HTH
Brett
-- 
Brett Porter
bporter AT rabble DOT uow DOT edu DOT au
http://www.geocities.com/CollegePark/Union/3596
	Humour, Programming, and more.
- Raw text -