首页 > 解决方案 > C - 如何在 getopts 中读取多个参数?

问题描述

我创建了一个 C 文件,它在处理一个参数时可以正常工作。如何在 getopts 中提取多个参数?

单参数运行良好:

test -c 3 -t 1101  -i 1S

我想阅读这样的多个论点:

test -c 3 -t 1101 1102 1103 -i 1S

下面是getops的代码:

   struct option long_options[] =
   {
      {"testCase", required_argument, 0, 't'},
      {"interval", required_argument, 0, 'i'},
      {"cell", required_argument, 0, 'c'},
      {"help", no_argument, 0, 'h'},
      {0, 0, 0, 0}
   };
   optind = 0;
   while (1)
   {
      int option_index = 0;
      z = getopt_long(argc, argv, ":t:i:c:", long_options, &option_index)
      
      ...

标签: carguments

解决方案


推荐阅读