C getopt multiple value

前端 未结 5 895
隐瞒了意图╮
隐瞒了意图╮ 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 06:15

    If you must, you could start at argv[optind] and increment optind yourself. However, I would recommend against this since I consider that syntax to be poor form. (How would you know when you've reached the end of the list? What if someone has a file named with a - as the first character?)

    I think that it would be better yet to change your syntax to either:

    /a.out -i file1 -i file2 -i file3
    

    Or to treat the list of files as positional parameters:

    /a.out file1 file2 file3
    

提交回复
热议问题