Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: Can I tell my chess program to know the name of it's exe file.

Author: Dann Corbit

Date: 19:06:40 06/11/04

Go up one level in this thread


On June 11, 2004 at 20:51:35, Uri Blass wrote:

>On June 11, 2004 at 20:39:33, Joshua Shriver wrote:
>
>>
>>Parse your argv data.
>>
>>Believe argv[0] is the filename of the executable being run.
>>
>>int main(int argc, char *argv[])
>>{
>>
>>  printf("%s\n", argv[0]);
>>
>>  return 0;
>>}
>
>Based on Dann Corbit's post I cannot trust it so I think that I will not try to
>use it inspite of the fact that now it works because tomorrow with a new
>compiler it may stop to work.
>
>Here are Dann Corbit's words:
>
>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.
>
>Uri

Uri is correct.  A better version of the test program would look like this:

int main(int argc, char *argv[])
{
   if (argc > 0)
      printf("%s\n", argv[0]);
   else
      puts("program name unknown");
   return 0;
}



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.