參考鏈接: 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語言中檢查命令行參數