首页 > 其他 > 详细

6.可变参数问题-getopt函数

时间:2017-03-19 13:16:15      阅读:232      评论:0      收藏:0      [点我收藏+]

 

 

 1 #include <unistd.h>
 2 #include <stdio.h>
 3 int main(int argc, char * argv[])
 4 {
 5     
 6     int ch;
 7     printf("\n\n");
 8     printf("the initial value of optind:%d, and opterr: %d\n",optind,opterr);   //2.用来记录下一个检索位置,3.是否将错误信息输出到stderr
 9     printf("--------------------------\n");
10     
11     while ((ch = getopt(argc, argv, "ab:c:de::")) != -1)
12     {
13            printf("optind: %d\n", optind);
14            switch (ch) 
15            {
16                case a:
17                        printf("HAVE option: -a\n\n");   
18                        break;
19                case b:
20                        printf("HAVE option: -b\n"); 
21                        printf("The argument of -b is %s\n\n", optarg);          //1.用来保存选项的参数
22                        break;
23                case c:
24                        printf("HAVE option: -c\n");
25                        printf("The argument of -c is %s\n\n", optarg);
26                        break;
27                case d:
28                    printf("HAVE option: -d\n");
29                      break;
30               case e:
31                     printf("HAVE option: -e\n");
32                     printf("The argument of -e is %s\n\n", optarg);
33                   break;
34               case ?:
35                        printf("Unknown option: %c\n",(char)optopt);             //4.不在字符串optstring中的选项
36                        break;
37            }
38     }
39 
40 
41 }

 

6.可变参数问题-getopt函数

原文:http://www.cnblogs.com/girlblooding/p/6579629.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!