标签:
1、main函数的两个参数
main函数中两个参数的含义
1 int main(int argc, char *argv[]) 2 3 { 4 5 ... 6 7 }
#include "stdafx.h" #include "stdio.h" #include "stdlib.h" int main(int argc, char* argv[]) { printf("%d\n",argc); printf("%s\n",argv[0]); printf("%s\n", argv[1]); return 0; }
#include "stdafx.h" #include "stdio.h" #include "stdlib.h" int main(int argc, char* argv[]) { FILE *fp; char c; char s[20]; //char *a[2]; //a[0]= "C:\\Users\\samni\\Desktop\\test\\a.txt"; if (argc != 2) { printf("Error format,Usage: display filename1\n"); return 0; //键入了错误的命令行,结束程序的执行 } //if ((fp = fopen("C:\\Users\\samni\\Desktop\\test\\a.txt", "r")) == NULL) //if ((fp = fopen(a[0], "r")) == NULL) if ((fp = fopen(argv[1], "r")) == NULL) { printf("error!this file can not open\n"); } else { fgets(s,20,fp); //printf("%c\n", c); printf("%s\n", s); printf("succsed!\n"); } fclose(fp); system("pause"); //printf("%d\n",argc); //printf("%s\n",argv[0]); //printf("%s\n", argv[1]); //system("pause"); return 0; }
标签:
原文地址:http://www.cnblogs.com/alexliu2360/p/5701583.html