I think this is what you are trying to do:
Code:
int main(int argc, char *argv[])
{
// make sure that there is at least 1 argument
if (argc < 2) {
usage();
return 0; // quit the program
}
if (!strcmp(argv[1],"-i")) { // Check if the first argument is equal to -i
i();
}
else if (!strcmp(argv[1],"-h")) {
h(argv[2]);
}
else if (!strcmp(argv[1],"-r")) {
r();
}
else {
usage();
return 0;
}
return 0;
}
Note that you are misunderstanding the arguments. Let's say your program was run like the fillowing:
myprogram.exe -h hello
Now here is what your arguments look like:
argv[0] = "myprogram.exe"
argv[1] = "-h"
argv[2] = "hello"
In order to see if a string is equal to something, you cannot use ==, you need to use strcmp() like in my example.