小编Mar*_*ser的帖子

如何将整数作为命令行参数?

我已经阅读了一个getopt()示例,但它没有显示如何接受整数作为参数选项,就像cvalue在示例的代码中一样:

 #include <ctype.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>

 int
 main (int argc, char **argv)
 {
   int aflag = 0;
   int bflag = 0;
   char *cvalue = NULL;
   int index;
   int c;

   opterr = 0;

   while ((c = getopt (argc, argv, "abc:")) != -1)
     switch (c)
       {
       case 'a':
         aflag = 1;
         break;
       case 'b':
         bflag = 1;
         break;
       case 'c':
         cvalue = optarg;
         break;
       case '?':
         if (optopt == 'c')
           fprintf (stderr, "Option -%c requires …
Run Code Online (Sandbox Code Playgroud)

c getopt command-line-arguments

19
推荐指数
4
解决办法
8万
查看次数

标签 统计

c ×1

command-line-arguments ×1

getopt ×1