首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C语言 >

main函数带参数对实现文件的复制?解决方案

2012-04-04 
main函数带参数对实现文件的复制??????#includestdio.h#includestdlib.hvoid main(int argc,char *arg

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);
}
[解决办法]

C/C++ code
if((out=fopen(argv[2],"w"))==NULL);//LZ你应该看到这里多了分号了吧!{printf("cannot open outfile\n");exit(0);}
[解决办法]
今天上课刚写这个程序。正如楼上,你多了个分号。

热点排行