Name: Anonymous 2009-11-02 7:28
Hey guys.
Does anyone have a simple tutorial for using getopt?
Thank you!
Anon.
Does anyone have a simple tutorial for using getopt?
Thank you!
Anon.
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;
}