The POSIX C standard library way of handling command line parameters.

getopt(argc, argv, optstr) takes the command line arguments from argc and argv, and gets the list of allowed options from optstr.

It should be put inside a loop, run until getopt returns EOF. Inside the loop, if getopt() doesn't return EOF, it returns the option character found, and string pointer optarg has the option argument (if any) - for example -x foo will make getopt() return an 'x', and optarg points to string "foo".

For parsing longer arguments, the library has getopt_long()...