argc是命令行总的参数个数
char *argv[]是一个字符数组,其大小是int argc,主要用于命令行参数 argv[] 参数,数组里每个元素代表一个参数
可以利用vc debug,设置程序变量实现
例如设置成aaa bbbb
注意上面用空格分开,这样,如果程序对argc判断,可以输出参数值
if(argc > 1)
for(int i=1;i
编译后的程序名若是yxbs.exe
yxbs.exe a.txt,b.txt,c.txt
就传入了。
FILE *f1,*f2,*f3;
char name1[20],name2[20],name3[20];
if (argc >=2) strcpy(name1,argv[1]); // 传入
if (argc >=3) strcpy(name2,argv[2]);
if (argc >=4) strcpy(name3,argv[3]);
打开文件:
f1 = fopen(name1,"r");
f2 = fopen(name2,"r");
f3 = fopen(name3,"r");
。。。。。。
fclose(f1);fclose(f2),fclose(f3); // 关
argc
An integer specifying how many arguments are passed to the program from the command line. Because the program name is considered an argument, argc is at least 1.
argv
An array of null-terminated strings. It can be declared as an array of pointers to char (char *argv[ ] or wchar_t *argv[ ] for wmain) or as a pointer to pointers to char (char **argv or wchar_t **argv for wmain). The first string (argv[0]) is the program name, and each following string is an argument passed to the program from the command line. The last pointer (argv[argc]) is NULL.
让你的程序带参数运行的
argc 参数个数 argv 参数表