拷贝文件功能
代码说明: 我想编写一个程序,实现文件的拷贝,编译器是Microsoft Visual C++ 6.0, 但是每次只能fread到26个字节后再读就直接返回0了,本人甚是不解,有哪位高手帮忙看一下,不胜感激!谢谢!原代码:
#include<fcntl.h>
#include<stdio.h>
/*拷贝文件,参数为文件描述符*/
void mycpy(FILE *src, FILE *dst)
{
int a = 100, s, d;
char buf[1024];
while ((d = fread(buf, 1,4096, src)) > 0)
{
d = fread(buf, 1,1000, src);
printf("fread %d\n", d);
s =fwrite(buf, 1, d, dst);
printf("fwrite %d\n", s);
}
return;
}
int main(void)
{
FILE *fp1, *fp2;
fp1 = fopen("G:\\src.out","r");
if(fp1 == NULL)
{
printf("fopen G:BOCCOM.out ERROR\n");
return -1;
}
printf("fopen fp1 ok\n");
fp2 = fopen("G:\\dst.out", "w");
if(fp2 == NULL)
{
printf("G:\\src.out error\n");
return -1;
}
printf("fopen fp2 ok\n");
mycpy(fp1,fp2);
fclose(fp1);
fclose(fp2);
return 0;
}
[ 本帖最后由 喜子 于 2012-8-29 14:56 编辑 ]