main函数:
新建testmain.c
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
int main(int argc, char **argv)
{
int i,j;
i = atoi(argv[1]);
j = atoi(argv[2]);
printf("the program name is %s", argv[0]);
printf("the command line has %d argument:\n", argc);
printf("%d, %d\n",i,j);
return 0;
}
参数argc为main函数中所带的参数个数, argv[0]为参数名称, argv[1]、argv[2]……才是真正的参数
编译生成testmain可执行文件
运行:
the program name is ./mnt/usb/testmain (这是因为运行的程序就是 ./mnt/usb/testmain)
the command line has 3 argument (输入两个参数,加上 argv[0] 刚好3个)
10, 11 (输入的2个参数)