参考链接: Java中的命令行参数
c语言中检查命令行参数
Command line argument is a parameter supplied to the program when it is invoked. Command line argument is an important concept in C programming. It is mostly used when you need to control your program from outside. Command line arguments are passed to the main() method.
命令行参数是调用程序时提供给程序的参数。 命令行参数是C编程中的重要概念。 它主要用于需要从外部控制程序的情况。 命令行参数将传递给main()方法。
Syntax:
句法:
int main(int argc, char *argv[])
Here argc counts the number of arguments on the command line and argv[ ] is a pointer array which holds pointers of type char which points to the arguments passed to the program.
这里argc计算命令行上的参数数量,而argv[ ]是一个指针数组,其中保存着char类型的指针,该指针指向传递给程序的参数。
命令行参数示例 (Example for Command Line Argument)
#include <stdio.h>
#include <conio.h>
int main(int argc, char *argv[])
{
int i;
if( argc >= 2 )
{
printf("The arguments supplied are:\n");
for(i = 1; i < argc; i++)
{
printf("%s\t", argv[i]);
}
}
else
{
printf("argument list is empty.\n");
}
return 0;
}
Remember that argv[0] holds the name of the program and argv[1] points to the first command line argument and argv[n] gives the last argument. If no argument is supplied, argc will be 1.
请记住, argv[0]保存程序的名称, argv[1]指向第一个命令行参数,而argv[n]给出最后一个参数。 如果未提供任何参数,则argc将为1。
翻译自: https://www.studytonight.com/c/command-line-argument.php
c语言中检查命令行参数