码迷,mamicode.com
首页 > 其他好文 > 详细

argc AND argv[0]

时间:2020-06-26 20:16:17      阅读:44      评论:0      收藏:0      [点我收藏+]

标签:html   pre   count   with   argc   include   specific   cto   cut   

reference: http://crasseux.com/books/ctutorial/argc-and-argv.html

argc stands for argument counts.

the "v" of argv[] stands for vector, and argv stands for the specific parameter when you input in command. We could test them with the following code.

Notice: when we execute the following program, it should be executable file. e.g. it should be ./a a b c, not gcc -o ab a.cpp

#include <stdio.h>

int main (int argc, char *argv[])
{
  int count;

  printf ("This program was called with \"%s\".\n",argv[0]);

  if (argc > 1)
    {
      for (count = 1; count < argc; count++)
    {
      printf("argv[%d] = %s\n", count, argv[count]);
    }
    }
  else
    {
      printf("The command had no other arguments.\n");
    }

  return 0;
}

 

argc AND argv[0]

标签:html   pre   count   with   argc   include   specific   cto   cut   

原文地址:https://www.cnblogs.com/defoliate/p/13195986.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!