Question

my code looks like this:

if((strcmp(argv[1], "-a") == 0) && (argc == 3)) {
    /* my code */
} else if((strcmp(argv[1], "-b") == 0) && (argc == 3)) {
    /* my code */
} ...

And so on. Is this the only way to work around comparing args? I read someplace that it can be done using a loop, but I can't seem to figure out how. Right now, my code is kind of saturated with these if statements.

Thank you, this is my first question, I won't be asking one again, I like to figure things out on my own. But right now, time is of the essence.

So, is there a crispier way to do this?

Was it helpful?

Solution

There is a C function for that: getopt()

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top