On 11/7/2012 3:21 PM, Leslie S Satenstein wrote:
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
*
Hi,
What I meant to say, but did not express clearly, was why reinvent the
wheel when there was already a function to do the job for you.
Anyhoo, I'm glad you found the bug and the fix for it.
David
_______________________________________________
mlug mailing list
[email protected]
https://listes.koumbit.net/cgi-bin/mailman/listinfo/mlug-listserv.mlug.ca