标签:style blog http color 使用 strong
1 #include <stdio.h> 2 #include <unistd.h> 3 4 int main(int argc, char **argv) 5 { 6 int ch; 7 opterr = 0; 8 while ((ch = getopt(argc,argv,"a:bcde::f"))!=-1) 9 { 10 switch(ch) 11 { 12 case ‘a‘: 13 printf("option a:‘%s‘\n",optarg); 14 break; 15 case ‘b‘: 16 printf("option b :b\n"); 17 break; 18 case ‘e‘: 19 printf("option e:‘%s‘\n",optarg); 20 break; 21 default: 22 printf("other option :%c\n",ch); 23 } 24 } 25 printf("optopt +%c\n",optopt); 26 27 return 1; 28 }
运行结果:
1 ~ Home$ ./c -a 2 other option :? 3 optopt +a 4 ~ Home$ ./c -a 123 5 option a:‘123‘ 6 optopt +a 7 ~ Home$ ./c -a123 8 option a:‘123‘ 9 optopt +a 10 ~ Home$ ./c -b 11 option b :b 12 optopt +b 13 ~ Home$ ./c -cde 14 other option :c 15 other option :d 16 other option :? 17 optopt +e 18 ~ Home$ ./c -e 19 other option :? 20 optopt +e 21 ~ Home$ ./c -e123 22 option e:‘123‘ 23 optopt +e 24 ~ Home$ ./c -e 456 25 option e:‘456‘ 26 optopt +e 27 ~ Home$ ./c -f 28 other option :f 29 optopt +f 30 ~ Home$ ./c -a 123 -bcdf -e 456 31 option a:‘123‘ 32 option b :b 33 other option :c 34 other option :d 35 other option :f 36 option e:‘456‘ 37 optopt +e
reference:
http://vopit.blog.51cto.com/2400931/440453
[c language] getopt,布布扣,bubuko.com
标签:style blog http color 使用 strong
原文地址:http://www.cnblogs.com/galoishelley/p/3818661.html