BW> One reason I really liked using switch() is because it's easy
BW> to add another case...
BW> switch(something) {
BW> case '/h': case '/H': case '-h': case '-H':
BW> case '/?': case '-?':
BW> // do something
BW> break;
BW> case '/x': case '/X': case '-x': case '-X':
BW> // do someother thing
BW> break;
BW> default:
BW> // do nothin
BW> }
BW> but I guess using your example I could use some ors...?
BW> if( compare == "/h" || compare == "/H" ||
BW> compare == "-h" || compare == "-H" ||
BW> compare == "/?" || compare == "-?"
BW> )
BW> // do the /h thing
BW> else
BW> if(compare == "/x" || compare == "/X" ||
BW> compare == "-x" || compare == "-X"
BW> )
BW> // the /x stuff
BW> else
BW> // do the default
Not only that, but you could create a whole new function to
assist in your comparisons, using a table and a switch.
Now you can process for all command line switches in a single
swell foop.
int Command_parameters(char *szCmnd, char **pszCases, int iCase)
{
String Str = szCmnd;
for(;iCase > 0; ICase--)
if(Str == pszCases[iCase - 1])
return ICase;
return 0;
}
int main(int argC, char **argV)
{
char **pszOK =
{ "/a", "/A", "/b", "/B", "/c", "/C", "/d", "/D" };
int iSwitches = 8;
for(int iArg = 1; iArg < argC; iArg++)
{
switch(Command_parameters(argV[iArg], pszOK, iSwitches))
{
case 1: case 2: ConfigureFor_A_Switch(); break;
case 3: case 4: ConfigureFor_B_Switch(); break;
case 5: case 6: ConfigureFor_C_Switch(); break;
case 7: case 8: ConfigureFor_D_Switch(); break;
default: ConfigureFor_NO_Switch(); break;
}
}
return 0;
}
> ] Their numbers are 664 and 668, the neighbors of the beast...
---
---------------
* Origin: *YOPS ]I[* 3.1 GIG * RA/FD/FE RADist * Milwaukee, WI (1:154/750)
|