在C命令行参数 [英] Command line arguments in C

查看:114
本文介绍了在C命令行参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个计划与命令行给出的值10,20,30执​​行。

I have this program execute with the values 10,20,30 given at command line.

int main(int argc , char **argv)
 { 
  printf("\n Printing the arguments of a program \n");
  printf("\n The total number of arguments in the program is %d",argc);
   while(argc>=0)
    { 
     printf("%s   ",argv[argc]);
     argc--;
     }
     return 0;
  }    

的输出是
 的参数中的节目的总数为4(空)30 20 10 ./a.out

The outputs is The total number of arguments in the program is 4(null) 30 20 10 ./a.out

如果这样做(空)来自??

Where did that (null) come from ??

推荐答案

的argv [0] 应该是能够识别该程序存在(尽可能)跑。 的argv [1] 的argv [ARGC-1] 是实际上是在命令行中输入的参数。 ARGV [ARGC] 要求是一个空指针(§5.1.2.2.1/ 2)。

argv[0] is (to the extent possible) supposed to be something that identifies the program being run. argv[1] through argv[argc-1] are the arguments that were actually entered on the command line. argv[argc] is required to be a null pointer (§5.1.2.2.1/2).

这篇关于在C命令行参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆