C getopt multiple value

前端 未结 5 888
隐瞒了意图╮
隐瞒了意图╮ 2020-11-29 05:24

My argument is like this

./a.out -i file1 file2 file3

How can I utilize getopt() to get 3 (or more) input files? I\'m doing s

5条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-29 05:50

    I looked and tried the code above, but I found my solution a little easier and worked better for me:

    The handling I wanted was:

    -m mux_i2c_group mux_i2c_out
    

    (2 arguments required).

    Here's how it panned out for me:

    case 'm':
        mux_i2c_group = strtol(optarg, &ch_p, 0);
    
        if (optind < argc && *argv[optind] != '-'){
            mux_i2c_out = strtol(argv[optind], NULL, 0);
            optind++;
        } else {
            fprintf(stderr, "\n-m option require TWO arguments  "
                            "\n\n");
            usage();
        }
    
        use_mux_flag = 1;
        break;
    

    This grabbed the first value form me as normal and then just looked for the second, REQUIRED value.

提交回复
热议问题