这里使用​​int fputc(int ch, FILE *fp)​​​ 和 ​​int fgetc(FILE *fp)​​ 进行文本文件的读取和复制。

#define _CRT_SECURE_NO_WARNINGS 

#include<stdio.h>

int fbcopy(FILE *fpdest, FILE *fpsrc);

int main(void)
{
FILE *fpdest = NULL, *fpsrc = NULL;

int sum_num = fbcopy(fpdest, fpsrc);

if (sum_num != -1) {
printf("总字节数目为:%d\n", sum_num);
} else {
printf("操作失败!!%d\n", sum_num);
}

return 0;
}

int fbcopy(FILE *fpdest, FILE *fpsrc)
{
char get_char;
int sum_num = 0;

fpsrc = fopen("fuck.dat", "rb");
if (fpsrc == 0) {
printf("打开文件失败!!!!");
return -1;
}

fpdest = fopen("copy_success.txt", "wb");
if (fpdest == 0) {
printf("打开文件失败!!!!");
return -1;
}

while ((get_char = fgetc(fpsrc)) != EOF) {
fputc(get_char, fpdest);
sum_num++;
}

fclose(fpsrc);
fclose(fpdest);
return sum_num;
}