vc++6.0 自编的函数没有 实现想 DOS下的copy 命令 不知道错在哪里 希望有人可以帮我帮我

jaedongjuly 2012-04-10 04:08:19
#include<stdio.h>
#include<stdlib.h>
void filecp(FILE *,FILE *);

main(int argc,char **argv)
{FILE *fpin=NULL, *fpout=NULL;

if(argc==3)
{ if((fpin=fopen(argv[1],"r"))==NULL)
{printf("can't open this file !\n"); exit(0);}
if((fpout=fopen(argv[2],"w"))==NULL)
{printf("can't open this file !\n"); exit(0);}
filecp(fpin,fpout);
fclose(fpin); fclose(fpout);
}
else
printf("Error!\n");
}


void filecp(FILE *fpin,FILE *fpout)
{ char ch='\0';
ch=fgetc(fpin);
while(feof(fpin)==0)
{ fputc(ch,fpout);
ch=fgetc(fpin);
}

}
程序名为mycopy.c

在命令行下
C:\mycopy G:\lxwe\stu01.txt G:\lxwe\stu02.txt
stu01.txt 和stu02.txt 文件存在 文件的路径名正确

我就是不知到错在哪里
...全文
96 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
jaedongjuly 2012-04-10
  • 打赏
  • 举报
回复
我是一个初学者。没有看明白您的回答。
这个程序到底改成什么
赵4老师 2012-04-10
  • 打赏
  • 举报
回复
不要把
fopen("...","...");fscanf,fprintf,fclose //读时把\r\n替换成\n,写时把\n替换成\r\n;读到\x1a就设置EOF;读写的内容当字符看待

fopen("...","...b");fread,fwrite,fclose //不作以上替换,遇到\x1a仍继续读;读写的内容当字节看待
弄混了
jaedongjuly 2012-04-10
  • 打赏
  • 举报
回复
不行 没有用
evencoming 2012-04-10
  • 打赏
  • 举报
回复
if((fpin=fopen(argv[1],"r"))==NULL)
{printf("can't open this file !\n"); exit(0);}
if((fpout=fopen(argv[2],"w"))==NULL)
=>
if((fpin=fopen(argv[1],"rb"))==NULL)
{printf("can't open this file !\n"); exit(0);}
if((fpout=fopen(argv[2],"wb"))==NULL)

使用fgetc,fputc打开的时候必须有 “b”

69,371

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧