main函数带参数对实现文件的复制??????
#include<stdio.h>
#include<stdlib.h>
void main(int argc,char *argv[])
{
FILE *in,*out;
char ch;
if(argc!=3)
{
printf("You forgot to enter a filename\n");
exit(0);
}
if((in=fopen(argv[1],"r"))==NULL)
{
printf("cannot open infile\n");
exit(0);
}
if((out=fopen(argv[2],"w"))==NULL);
{
printf("cannot open outfile\n");
exit(0);
}
while(!feof(in))
{
fputc(fgetc(in),out);
}
fclose(in);
fclose(out);
}
设程序名a.c ,在doc命令行下输入a.exe file.txt file2.txt。且路径正确。为什么有错???输出cannot open outfile!求解释???
[解决办法]
if((out=fopen(argv[2],"w"))==NULL); // 多了个分号
{
printf("cannot open outfile\n");
exit(0);
}
[解决办法]
if((out=fopen(argv[2],"w"))==NULL);//LZ你应该看到这里多了分号了吧!{printf("cannot open outfile\n");exit(0);}
[解决办法]
今天上课刚写这个程序。正如楼上,你多了个分号。