Skip to content

getopt.h #20

Answered by chandrakant100
Ank1taS asked this question in Q&A
Discussion options

You must be logged in to vote

The getopt() function is a builtin function in C and is used to parse command line arguments.

getopt(int argc, char *const argv[], const char *optstring)

`optstring` is simply  a list of characters, 
each representing a single character option.

Return Value: The getopt() function returns different values:

  • If the option takes a value, that value is pointerto the external variable optarg.
  • -1 if there are no more options to process.
  • ?when there is an unrecognized option and it stores into external variable optopt.
  • If an option requires a value (such as -f in our example) and no value is given, getopt normally returns ?.
    By placing a colon as the first character of the options string, geto…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by chandrakant100
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
good first issue Good for newcomers help wanted Extra attention is needed question Further information is requested
2 participants