سؤال

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?

هل كانت مفيدة؟

المحلول

There is a C function for that: getopt()

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top