Prevent getopt_long crash on unknown options
When you parse commandline arguments in C using getopt_long don't forget to terminate the list of options.
Otherwise it will mostly work, but crash when user enters an invalid long option.
static const struct option long_options[] = {
    ...
    {NULL, 0, NULL, 0}, // don't forget the terminator
};Written by Kornel
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
 #C 
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#