-
Command Line Arguements
I am trying to write a program which uses command line arguements and options. The part I am have trouble with is arranging all the different combinations. For example the options are as follows: -c, -a, -t, -p, -cp, -ca, -ct, -ctp, -tca, -tcap, and etc... for every possible combination. Or you can have the options seperated like -c -a -t, etc. My problem is this. How should I write the code so that when an option is chosen such as -cta, it wouldnt matter if the user put in that of -atc. What I am thinking is that I should convert the characters to the hex or decimal format and the sum of them would be the same no matter what combination..but how would I do that? Or should I do it someother way? Please help... Thanks in advance!
-Chris
-
I haven't tried compiling this:
Code:
for( i = 1; i < argc; i++ ) {
if( argv[i][0] == '-' ) {
for( j = 1; j < strlen( argv[i] ); j++ ) {
switch( argv[i][j] ) {
case 'a':
// Do something...
break;
case 'c':
// Do something...
break;
case 't':
// Do something...
break;
case 'p':
// Do something...
break;
}
}
}
}
-
It works!
Thank you so much for the quick replies. They both worked great. Thanks again for your help!