User Tools

Site Tools


c

This is an old revision of the document!


getopt

#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
 
int main (int argc, char** argv) {
 
	int o;
	int opt_a;
	char* opt_c;
	while ((o = getopt (argc, argv, "abc:")) != -1) {
		switch (o) {
		case 'a':
			opt_a = 1;
			printf("a=yes\n");
			break;
		case 'c':
			opt_c = optarg;
			printf("c='%s'\n",opt_c);
			break;
		case '?':
			exit(1);
		}
	}
	argc -= optind; argv += optind; // throw away option arguments
 
}
c.1248378087.txt.gz · Last modified: 2009/07/23 12:41 by tkbletsc

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki