Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

[C] getopt

Name: Anonymous 2009-11-02 7:28

Hey guys.

Does anyone have a simple tutorial for using getopt?
Thank you!

Anon.

Name: Anonymous 2009-11-02 7:32

Name: Anonymous 2009-11-02 7:33

http://linux.die.net/man/3/getopt
scroll down to ,,Example''.

Name: Anonymous 2009-11-02 7:36

you're kidding? .......right?

Name: Anonymous 2009-11-02 7:42

>>1,3-4
SPAWHBTC

Name: Anonymous 2009-11-02 16:57

I need something with optional arguments.

Name: Anonymous 2009-11-02 16:58

>>6
1/10

Name: Anonymous 2009-11-02 17:32

Dear >>1-san, please feel free to make use of this function so that you can just have you options defined in the option and not have to maintain a separate string for short opts. For this though you'll get a short opt for every long opt, and some other shit which I cant remember. Like how stuff is returned.

/* creates optstring arg (short opts) from option struct  */
char *mkoptstr(struct option *opt) {
  int n = 0;
  char *optstring,*p;
  struct option *o = opt;
  while(o->name || o->has_arg || o->flag || o->val) {
    n += 1 + o->has_arg;
    if(o->flag)
      return NULL; /* fail because not returning o->val */
    o++;
  }
  p = optstring = malloc(n+1);
  o = opt;
  while(o->name || o->has_arg || o->flag || o->val) {
    *p++ = o->val;
    n = o->has_arg;
    while(n--)
      *p++ = ':';
    o++;
  }
  *p = 0;
  return optstring;
}

Name: Anonymous 2010-12-06 9:59

Back to /b/, ``GNAA Faggot''

Name: Anonymous 2011-01-31 20:34

<-- check em dubz

Name: Anonymous 2013-01-19 21:00

/prog/ will be spammed continuously until further notice. we apologize for any inconvenience this may cause.

Don't change these.
Name: Email:
Entire Thread Thread List