72f8ba24304c4648c18e11f0aa2287f2

I learn getopt, but it should have the most of other function. So I will add them in the future.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#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 !

F1e3ab214a976a39cfd713bc93deb10f

Tj Holowaychuk

April 8, 2009, April 08, 2009 15:16, permalink

No rating. Login to rate!

wtf lol.. this is not action script this is C

72f8ba24304c4648c18e11f0aa2287f2

gaoweige.blogspot.com

April 8, 2009, April 08, 2009 23:08, permalink

No rating. Login to rate!

I am sorry!
Thanks Tj Holowaychuk.

F1e3ab214a976a39cfd713bc93deb10f

Tj Holowaychuk

April 8, 2009, April 08, 2009 23:36, permalink

No rating. Login to rate!

Did it always default to AS? that almost caught me too I swear it used to default to something else

72f8ba24304c4648c18e11f0aa2287f2

gaoweige.blogspot.com

April 9, 2009, April 09, 2009 15:18, permalink

No rating. Login to rate!

What's "AS" mean? Can you please rephrase it for me? Thanks!

F1e3ab214a976a39cfd713bc93deb10f

Tj Holowaychuk

April 9, 2009, April 09, 2009 15:23, permalink

No rating. Login to rate!

actionscript sorry

Your refactoring





Format Copy from initial code

or Cancel