Author: Dann Corbit
Date: 10:03:43 06/11/04
Go up one level in this thread
On June 11, 2004 at 09:42:25, Uri Blass wrote: >On June 11, 2004 at 09:04:28, Rémi Coulom wrote: > >>On June 11, 2004 at 08:30:29, Uri Blass wrote: >> >>>I have a version of movei that is movei00_8_236.exe >>> >>>It is using a lot of files when the number 236 is in it. >>> >>>When I change to movei00_8_237.exe I want the new version to use files with the >>>number 237 in it(the reason is that otherwise if I put both 236.exe and 237.exe >>>in the same folder they use the same files and can change the same book files >>>and I do not want 237 to learn to change it's book from games of 236). >>> >>>Of course it is possible to put 236 and 237 in different folders but I do not >>>like this solution. >>> >>>I think that the best solution is to tell the program to read the name of the >>>exe file and copy it to a string and use it when it decide about the names of >>>the files that it reads or create. >>> >>> >>>The question is how to do it. >>> >>>Uri >> >>if your main function is >> >>int main(int argc, char *argv[]) >> >>then argv[0] is the name of the exe >> >>Rémi > >Thanks > >It is >__cdecl main(void) > >I do not remember why I need the cdecl and it was a long time ago but if I >remember correctly I needed it when I tried to change the .c files to .cpp >files(I do not use C++ code but only C but I find it easier to do things with >cpp code(for example I know from experience that checking bounds does not work >correctly with files that end with .c). Some compilers do some rudimentary bounds checking. However, the reliable way to do it is to use a bounds checker. There are lots of them. >Having >__cdecl main(int argc, char *argv[]) has no compilation error and I find that >argv[0] does not give me only the name of the exe file but also the name of all >the path but it is not a big problem to write a function to return the last >number of a string in case that the string end with a number and to return 0 in >case that the string does not end with a number. The function is simple. This information from the C-FAQ may be relevant: 19.31: How can my program discover the complete pathname to the executable from which it was invoked? A: argv[0] may contain all or part of the pathname, or it may contain nothing. You may be able to duplicate the command language interpreter's search path logic to locate the executable if the name in argv[0] is present but incomplete. However, there is no guaranteed solution. References: K&R1 Sec. 5.11 p. 111; K&R2 Sec. 5.10 p. 115; ISO Sec. 5.1.2.2.1; H&S Sec. 20.1 p. 416. 19.32: How can I automatically locate a program's configuration files in the same directory as the executable? A: It's hard; see also question 19.31 above. Even if you can figure out a workable way to do it, you might want to consider making the program's auxiliary (library) directory configurable, perhaps with an environment variable. (It's especially important to allow variable placement of a program's configuration files when the program will be used by several people, e.g. on a multiuser system.)
This page took 0 seconds to execute
Last modified: Thu, 15 Apr 21 08:11:13 -0700
Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.