I'm trying to figure how the best way of checking for certain flags. I have a program that can be ran standard without the -a or -b flag. If the user wants to run the -a flag, he/she must include 4 values after it. The -a flag can be called anywhere but must have the 4 values follwoing the call. The -b flag can be called anywhere as long as it does not conflict with flag -a option. A filename can also be included. I know argc counts the number of params main starts with. If certain flags are called, there should be certain checks to make sure the correct amount of input is included. I'm not quite sure how to check for this right now. I haven't worked with multiple arguments from main before and checking for all cases. Any help would be great. Thank you. Here is just a sample program of what I tested so far to see what values are stored where. You can assumed argv[0] is the calling program, so values from arg[1] and above. At most argc can at most 7. Any more than that would be terminiation of the program.


Code:
#include <stdio.h>

main(int argc, char** argv)
{
    int i;

    printf("argc = %d\n", argc);

    for (i = 0; i < argc; i++)
        printf("argv[%d] = \"%s\"\n", i, argv[i]);


    printf("\n");

    // form of input
    // prog fname -a val1 val2 val3 val4
    // or
    // prog -a val1 val2 val3 val4 fname
    //
    // also -b flag can be called and it can be placed anywhere

   return(0);
}