argv substr() question

Hello all,
I am mostly a c++ programmer, now programming UPC on a cray so please bare with me.
I am trying to parse a string from argv and am having a few troubles.
ex: entering the following "./CraPov -[option] povrayfile.pov"
I would like to parse argv to return [povrayfile] (without the ".pov" extention)

I was wondering if there is a simple function to do this for me or if i have to use substr() and write my own. Thankz for your help in advance.

Lot's of suggestions here. All seem to trip on the issue of embedded periods. It would seem that the key item isn't just the period, but the slash. As several posts have pointed out, the file name could also be a path.

if (*occ == '.') /* The file name contained at least one period so we'll end the string at the last one */
*occ = 0;

tfn = strdup (occ); /* Make a string that is the desired filename */
free (Fn); /* Free the scratch buffer that contained the original path */
return (tfn);
}

Let me caution that this is dangerous. Instead of arbitrarily dropping the extension, the function should check that the extension is an allowed type. If so, it can then drop the extension, if not the function should probably return NULL so that the calling function can inform the user that an an invalid file was entered. To make this happen, replace:

Cray programmer huh? I'm and old CDCer with experience on everything that they made after the 3000 series. Another common poster here is grg99 who goes back to CDC's 160A days! How about sending me a note offline -- my e-mail address is in my profile.

kent,
sorry it took so long to respond(halloween &all)
overall this seems to work quite well...
though the options are still giving me bit of a headache

i am trying to get the arguments before the povfile
i have a working version within main but i'm trying
like hell to get it into a function with no luck
i just don't know how to increment PovOp correctly
any help would be greatly appreciated

If you want the function to build the options table just as main() does now:

Just move the code in main() to the function and call it as GetOptions (argc, argv); Note that main() doesn't really BUILD an options table. It constructs a string that is the concatenation of all of the options on the command line. (This is probably not real useful to you.) The reason that the function seems to be failing is that the function call:

Options = GetOptions(argv[1],argc-1);

advances to start with the first parameter after the command name by incrementing the index and decrementing the count. GetOptions() and main() are hard-coded to look for a parameter by position. Note that main checks by "if (argc > 2)" and "if (argc > 3)". The functions uses these exact same checks (with variable *pl*). *pl* is derived from OpLen, which has the value of argc-1 so you seem to miss the last options parameter.

Featured Post

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Preface
I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…

This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…