내맘대로
C언어에서 옵션처리
Tran
2009. 5. 27. 10:21
1: #include <stdio.h>2: #include <string.h>3: #include <stdlib.h>4: #include <unistd.h>5:6: int main(int argc, char **argv)7: {8: char optstring[1024];
9: extern char *optarg;10: int optchar;
11:12:13: memset(optstring, 0x00, sizeof(optstring));
14:15: sprintf(optstring, "%s", "d:h:");16:17: while((optchar = getopt(argc, argv, optstring)) != EOF)
18: {19:20: switch(optchar)
21: {22: case 'd':
23: printf("option d = [%s] \n", optarg);24: break;
25:26: case 'h':
27: printf("option h = [%s] \n", optarg);28: break;
29:30: default :
31: break;
32: }33: }34:35: printf("End\n");36:37: return 0;
38: }
입니다.