/* ********************************************************************** */ /* * * */ /* * getopt_example.c * */ /* * * */ /* ********************************************************************** */ /* * * */ /* * This program shows how to use getopt. * */ /* * * */ /* ********************************************************************** */ /* * * */ /* * 06/06/2006 - Program Created * */ /* * * */ /* ********************************************************************** */ #include #include #include #include #include #include #include #include #include #include #define TRUE 1 #define FALSE 0 #define MAX_FCOUNT 8192 /* ********************************************************************** */ /* * Function: main * */ /* * * */ /* * Process command line options. * */ /* ********************************************************************** */ int main(argc, argv) int argc; char **argv; { int showsize = FALSE; /* "-s" flag */ int showlong = FALSE; /* "-l" flag */ int i; /* loop variable */ char c; /* Current option */ /* Process command line args */ while ((c = getopt(argc, argv, ":sl")) != -1) { switch (c) { case 's': showsize = TRUE; break; case 'l': showlong = TRUE; break; case '?': fprintf(stderr, "Invalid option -%c\n", optopt); exit(1); break; } } if (showsize) printf("-s option was used\n"); if (showlong) printf("-l option was used\n"); for (i = optind; i < argc; i++) { printf("remaining arg: %s\n", argv[i]); } exit(0); }