vc++6.0 自编的函数没有 实现想 DOS下的copy 命令 不知道错在哪里 希望有人可以帮小弟我帮小弟我
vc++6.0 自编的函数没有 实现想 DOS下的copy 命令 不知道错在哪里 希望有人可以帮我帮我
#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 文件存在 文件的路径名正确
我就是不知到错在哪里
------解决方案--------------------
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”
------解决方案--------------------
不要把
fopen("...","...");fscanf,fprintf,fclose //读时把\r\n替换成\n,写时把\n替换成\r\n;读到\x1a就设置EOF;读写的内容当字符看待
和
fopen("...","...b");fread,fwrite,fclose //不作以上替换,遇到\x1a仍继续读;读写的内容当字节看待
弄混了
#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 文件存在 文件的路径名正确
我就是不知到错在哪里
------解决方案--------------------
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”
------解决方案--------------------
不要把
fopen("...","...");fscanf,fprintf,fclose //读时把\r\n替换成\n,写时把\n替换成\r\n;读到\x1a就设置EOF;读写的内容当字符看待
和
fopen("...","...b");fread,fwrite,fclose //不作以上替换,遇到\x1a仍继续读;读写的内容当字节看待
弄混了