4 ms·
I always write my usage printing routine to take a FILE pointer, similar to the following, static void usage(const char *arg0, FILE *fp); and then at the ve
by wahern 3y ago
I always write my usage printing routine to take a FILE pointer, similar to the following,
static void usage(const char *arg0, FILE *fp);
and then at the very end of main's getopt switch something like,
case 'h':
usage(argv[0], stdout);
return 0;
default:
usage(argv[0], stderr);
return EXIT_FAILURE;
}
By default getopt prints (to stderr) a one line message for unknown options or missing arguments, so I usually don't bother catching ':' or '?' explicitly.