I have a program that can take in 3 arguments. They can be called in almost any order and they can be invoked more than once. I'm trying to use a switch statment to determin which case is called, but the problem is each flag also takes in a parameter and the main param that the program calls is shifted everytime a flag is called. I'm really not sure how to handle this.
test -c 35 //counts the number of 1's in base 2 for 35
test -c -s 3 35 //sets the 3 value of the base 2 number of 35 and then count up the number of 1's // base 2 of 35 = 100011 so if you set the 3rd bit it would be coming from the Right hand side so the value will then be 100111
test -c -s 3 -z 2 35 //sets the 3rd bit to 1 and then 2nd bit to 0 of the value 35
and so fourth. . . . I have functions to handle these sets, but I'm unsure how to handle every possible case. If it wasn't bad enough, the -s and -z can be called multiple times and they would set all values until the main Param value in this case, 35 is called before it prints out the value in base 2.
using namespace std;
int main(int argc, char **argv)
int i,set, zero, number, lenght, count;
for(i = 1; i < argc; i++)
//checks for the - symbol and determines through the switch what flag was called
if(argv[i] == '-')
cout << "C flag was called" << "\n";
cout << "S flag was called" << "\n";
cout << "Z flag was called" << "\n";
//unknown flag called
cout << "Invalid Flag" << "\n";
if(argc == 1)
cout << "Enter At Least 1 Parameter " << "\n"