I read the GNU manual and found a short example that I think will help you get started well:
Directly from the manual:
#include <config.h>
#include "system.h"
const char *program_name;
static const struct option longopts[] =
{
{ "greeting", required_argument, NULL, 'g' },
{ "help", no_argument, NULL, 'h' },
{ "next-generation", no_argument, NULL, 'n' },
{ "traditional", no_argument, NULL, 't' },
{ "version", no_argument, NULL, 'v' },
{ NULL, 0, NULL, 0 }
};
static void print_help (void);
static void print_version (void);
int
main (int argc, char *argv[])
{
int optc;
int t = 0, n = 0, lose = 0;
const char *greeting = NULL;
program_name = argv[0];
setlocale (LC_ALL, "");
#if ENABLE_NLS
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);
#endif
atexit (close_stdout);
while ((optc = getopt_long (argc, argv, "g:hntv", longopts, NULL)) != -1)
switch (optc)
{
case 'v':
print_version ();
exit (EXIT_SUCCESS);
break;
case 'g':
greeting = optarg;
break;
case 'h':
print_help ();
exit (EXIT_SUCCESS);
break;
case 'n':
n = 1;
break;
case 't':
t = 1;
break;
default:
lose = 1;
break;
}
if (lose || optind < argc)
{
if (optind < argc)
fprintf (stderr, _("%s: extra operand: %s\n"),
program_name, argv[optind]);
fprintf (stderr, _("Try `%s --help' for more information.\n"),
program_name);
exit (EXIT_FAILURE);
}
if (t)
printf (_("hello, world\n"));
else if (n)
printf (_("\
+---------------+\n\
| Hello, world! |\n\
+---------------+\n\
"));
else
{
if (!greeting)
greeting = _("Hello, world!");
puts (greeting);
}
exit (EXIT_SUCCESS);
}
static void
print_help (void)
{
printf (_("\
Usage: %s [OPTION]...\n"), program_name);
fputs (_("\
Print a friendly, customizable greeting.\n"), stdout);
puts ("");
fputs (_("\
-h, --help display this help and exit\n\
-v, --version display version information and exit\n"), stdout);
puts ("");
fputs (_("\
-t, --traditional use traditional greeting format\n\
-n, --next-generation use next-generation greeting format\n\
-g, --greeting=TEXT use TEXT as the greeting message\n"), stdout);
printf ("\n");
printf (_("\
Report bugs to <%s>.\n"), PACKAGE_BUGREPORT);
}
static void
print_version (void)
{
printf ("hello (GNU %s) %s\n", PACKAGE, VERSION);
puts ("");
printf (_("\
Copyright (C) %s Free Software Foundation, Inc.\n\
License GPLv3+: GNU GPL version 3 or later\
<http://gnu.org/licenses/gpl.html>\n\
This is free software: you are free to change and redistribute it.\n\
There is NO WARRANTY, to the extent permitted by law.\n"),
"2007");
}