If you read the getopt(3)
man page:
If getopt() does not recognize an option character, it prints an error message to stderr, stores the character in optopt, and returns '?'. The calling program may prevent the error message by setting opterr to 0.
So, getopt()
will return ?
if someone passes in an unrecognized option. You're looking for *
, which you will never receive. In C, *
does not act as a wildcard so this does not mean "any character".
Using default
here isn't the correct solution (although it will work), because this would also trigger on valid options for which you had not implemented a handler.