Just curious, are you only running on systems using glibc? If so why not use basename()?

http://www.gnu.org/software/libc/manual/html_node/Finding-Tokens-in-a-String.html#index-basename-577


On 10/31/2012 9:42 AM, Leslie S Satenstein wrote:
Hi Everyone

It was my being an Ass uming person.   My objective was that the program
name be that which was listed in the directory. Change the program name
and the error messages with the name change as well.

In the first lines of C code I had

char *progName= 1 + strrchr(argv[0],'/');   //Want one to the right of
the right most slash

This worked fine as I was always testing in the directory where I
created the program . (always need to prepend ./)

The corrected code will be clear to you at once about what I overlooked.

char *cp,*progName

progName=argv[0];
if (NULL != (cp=strrchr(argv[0],'/')))
    progName = cp+1;

When the program is activated via the $PATH,  there is no path
prepending the program name and hence, no path,  just a progName;

Sorry to bother you with such a trivial boo boo.

Regards
*
  Leslie
*
*Mr. Leslie Satenstein
*50 years in Information Technology and going strong.
Yesterday was a good day, today is a better day,
and tomorrow will be even better.

mailto:[email protected]
alternative: [email protected]
www.itbms.biz  www.eclipseguard.com





_______________________________________________
mlug mailing list
[email protected]
https://listes.koumbit.net/cgi-bin/mailman/listinfo/mlug-listserv.mlug.ca

Reply via email to