69,370
社区成员
发帖
与我相关
我的任务
分享
#include<stdio.h>
#include<string.h>
int main(int argc,char *argv[])
{
FILE *pr,*pw;
pr = fopen(argv[1],"r");
pw = fopen(argv[2],"w");
……
……
}
for (int i=0;i<argc;++i)
{
cout<<"参数"<<i<<":"<<argv[0]<<endl;//打印参数看看参数2正确与否
}
//------------------------------------------------------------
if (argv[1]==NULL||argv[2]==NULL)
cout<<"缺少参数"<<endl;
else
{
FILE *pr=NULL,*pw=NULL;
pr = fopen(argv[1],"r");
pw = fopen(argv[2],"w");
if (pr==NULL)
cout<<"文件1打开失败"<<endl;
if (pw==NULL)
cout<<"文件2打开失败"<<endl;
}
#include<stdio.h>
#include<string.h>
int main(int argc,char *argv[])
{
FILE *pr,*pw;
if (argc<3) {
printf("Usage: %s inputfile outputfile\n",argv[0]);
return 1;
}
pr = fopen(argv[1],"r");
if (NULL==pr) {
printf("Can not read file %s!\n",argv[1]);
return 2;
}
pw = fopen(argv[2],"w");
if (NULL==pw) {
fclose(pr);
printf("Can not create file %s!\n",argv[2]);
return 3;
}
……
……
return 0;
}
#include<stdio.h>
#include<string.h>
int main(int argc,char *argv[])
{
FILE *pr,*pw;
pr = fopen("aaa.txt",r");
pw = fopen("bbb.txt","w");
……
……
}