Hi David

It was not a problem of parsing the file name, but of forgetting that when the 
executable is called from the local directory,  my testing always had   a dot 
slash executable name.
my testing was always in the current directory, so the executable had a ./ 
prepended.

When I was doing some closer to final product,  I moved the execuable to 
$HOME/bin

Now, if I just typed executable name,  argv[0] did not have a prepended path.
so my search for the right most slash returned a NULL. 
The two liner was to test for a NULL, 

Here is the code fragment.

char *cp, *program;
if ( NULL!=( cp=strrchr(program=argv[o],'/'  )  )
    program = cp+1;

strrchr() is a function that I wrote and use frequently.  It returns the right 
most position for the character in a string, or NULL);
another is strrstr() returns the position of the right most substring of a 
string or NULL.

Whereever possible, I use library functions. For strings, always the functions 
listed in string.h  
For  subtasking, system timing, or file handling, I use time.h, unixstd.h or 
whatever is required.    
 
Thanks for reminding me of basename.   I also use access() to determine 
read/write permissions.



 

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
 

--- On Wed, 11/7/12, David Filion <[email protected]> wrote:

From: David Filion <[email protected]>
Subject: Re: [MLUG] program generating segmentation error messages Fixed.
To: [email protected]
Date: Wednesday, November 7, 2012, 9:13 AM


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
_______________________________________________
mlug mailing list
[email protected]
https://listes.koumbit.net/cgi-bin/mailman/listinfo/mlug-listserv.mlug.ca

Reply via email to