MarkdownPad Document
参考了http://blog.csdn.net/followingturing/article/details/7707584
还是根据实例来进行说明:
1 #include<stdio.h> 2 #include<stdlib.h> 3 4 int main(int argc,char *argv[]) 5 { 6 if(argc==1 || argc>2) 7 { 8 printf("Please input the name of the file 9 you want to edit, for example:./edit fillen\n"); 10 printf("argv[0] is %s\n",argv[0]); 11 } 12 13 if(argc==2) 14 { 15 printf("Now EDIT %s\n",argv[1]); 16 printf("argv[0] is %s\n",argv[0]); 17 printf("argv[1] is %s\n",argv[1]); 18 } 19 20 exit(0); 21 }
输入命令./edit时,argc==1;
输入命令./edit file.txt时,argc==2;
输入命令./edit时,argv[0]=="./edit";
输入命令./edit file.txt时,argv[0]=="./edit",argv[1]=="file.txt";
2017-2-4 23:10;20
原文:http://www.cnblogs.com/WangAoBo/p/6366600.html