switch/case? if/else? other?
Yes, getopt and forget everything (memory, not tested):
Code:
#include <stdio.h>
#include <stdlib.h>
#include <getopt.h>
int main(int nb, char * argv[])
{
int ch;
while ((ch = getopt(nb, argv, "a:b:c:d:" )) > 0)
{
switch (ch) {
case 'a':
case 'b':
case 'c':
case 'd':
fprintf(stderr, "option '%c', value = %s\n", ch, optarg);
break;
case ':':
fprintf(stderr, "option '%c', missing value\n", optopt);
break;
case '?':
fprintf(stderr, "invalid switch -%c\n", optopt);
}
}
while (optind < nb)
{
fprintf(stderr, "remaining option %s\n", argv[optind]);
optind ++;
}
}
Bookmarks