【C言語】コマンドラインパラメータ

コマンドライン引数

  • argc: 入力パラメータの数
    • パラメータは 1 ではなく、パス 1 は 2 です
  • argv[]: プログラムに渡される各パラメーターへのポインターの配列
    • argc[0]:番組名
    • argv[1]: 最初のコマンド ライン引数へのポインタ
#include <stdio.h>
int main(int argc, char *argv[])
{
    if(argc == 2){
        printf("%s", argv[1]);
    }
    else if(argc > 2){
        printf("Too much argument");
    }
    else{
        printf("no argument");
    }
}
./a.out testing
./a.out "test1 test2"

おすすめ

転載: blog.csdn.net/weixin_46143152/article/details/126688334
おすすめ