How does getopt(3) work, and what is the 'extern' variable optarg? How does getopt(3) work, and what is the 'extern' variable optarg? unix unix

How does getopt(3) work, and what is the 'extern' variable optarg?


From the manual:

An option character in this string can be followed by a colon (‘:’) to indicate that it takes a required argument.

So in your case your string for options should be "p:s" rather than "ps".