delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/09/07/22:59:33

Message-Id: <199709080258.MAA07539@rabble.uow.edu.au>
Subject: Re: Determining the path of the executable at runtime
To: karlos AT eznet DOT net (Karl Garrison)
Date: Mon, 8 Sep 1997 12:58:02 +1000 (EST)
Cc: djgpp AT delorie DOT com (DJGPP)
In-Reply-To: <927cd$11e31.3dd@news.eznet.net> from Karl Garrison at "Sep 2, 97 05:20:01 pm"
From: *** Brett *** <bporter AT rabble DOT uow DOT edu DOT au>
MIME-Version: 1.0

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


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019