#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
void usage();
int main(int argc, char* argv[])
{
char c;
char *name;
while ((c = getopt (argc, argv, "i:h")) != -1)
{
switch (c)
{
case 'i': /* interface name */
printf("I'm a i\n");
name = optarg;
printf("%c\n",name);
break;
case '?':
if (isprint (optopt))
fprintf (stderr, "Unknown option `-%c'.\n", optopt);
else
fprintf (stderr,
"Unknown option character `\\x%x'.\n",
optopt);
case 'h':
default:
usage();
exit(1);
}
}
}
void usage (void)
{
printf("Usage: ./counterdump <options> \n\n");
printf("Options: -i <iface> : interface name (default nf2c0)\n");
printf(" -h : Print this message and exit.\n");
}
Refactorings
No refactoring yet !
Tj Holowaychuk
April 8, 2009, April 08, 2009 15:16, permalink
wtf lol.. this is not action script this is C
gaoweige.blogspot.com
April 8, 2009, April 08, 2009 23:08, permalink
I am sorry!
Thanks Tj Holowaychuk.
Tj Holowaychuk
April 8, 2009, April 08, 2009 23:36, permalink
Did it always default to AS? that almost caught me too I swear it used to default to something else
gaoweige.blogspot.com
April 9, 2009, April 09, 2009 15:18, permalink
What's "AS" mean? Can you please rephrase it for me? Thanks!
I learn getopt, but it should have the most of other function. So I will add them in the future.