leiing 发表于 2016-08-04 17:10

getopt()如何解析-Wall这样的参数

本帖最后由 leiing 于 2016-08-09 14:43 编辑

看资料getopt只能解析短参数的,如-c -o -E,而getopt_long是解析长参数的,如--help。
但是像-Wall,只有一个横线,但有多个字符,如何解析?
int opt = 0;
static const char *optString = "Il:o:vh?";

opt = getopt( argc, argv, optString );
    while( opt != -1 ) {
      switch( opt ) {
            case 'I':
                break;
               
            case 'l':
                break;
               
            case 'o':
                break;
               
            case 'v':
                break;
               
            case 'h':   /* fall-through is intentional */
            case '?':
                display_usage();
                break;
               
            default:
                /* You won't actually get here. */
                break;
      }
      
      opt = getopt( argc, argv, optString );
    }
    谢谢。

MMMIX 发表于 2016-08-04 19:11

leiing 发表于 2016-08-04 17:10 static/image/common/back.gif
看资料getopt只能解析短参数的,如-c -o -E,而getopt_long是解析长参数的,如--help。
但是像-Wall,只有一个横线,但有多个字符,如何解析?


-Wall 通常等效于 -W -a -l -l

superwujc 发表于 2016-08-06 11:32

回复 1# leiing

getopt_long_only
   
页: [1]
查看完整版本: getopt()如何解析-Wall这样的参数