craaaft
craaaft

Reputation: 233

Getopt function without options just arguments

I am not sure how to use the getopt command in my scenario. I want the following input command:

mydiff file1 file2

So there are no options just the two filenames. Any idea on how to do that?

Upvotes: 0

Views: 263

Answers (1)

Darwin von Corax
Darwin von Corax

Reputation: 5246

If your program does not accept POSIX-style options, then alk has the right of it - you don't need getopt() if you have no options to get.

Per the getopt(3) manpage, once getopt() has exhausted the provided options (which, being options, may be zero in number), it returns (int) -1 and sets optind to the index of the first non-opt argument in argv[] which, in your example, would be argv[1] -> file1.

Upvotes: 1

Related Questions