在C语言中怎样实现文本文件的复制?

来源:百度知道 编辑:UC知道 时间:2024/05/14 17:07:57
比如将 E盘的 学习.txt 复制到D盘怎样实现呢?

#include "stdio.h"
#include "conio.h"

int main(void)
{
FILE *fp1, *fp2;
char ch;

if ((fp1 = fopen("c:\\学习.txt", "rb")) == NULL)
{
printf("can not open source file.\n");
return 1;
}
if ((fp2 = fopen("d:\\学习.txt", "wb")) == NULL)
{
printf("can not open destination file.\n");
fclose(fp1);
return 1;
}

while (!feof(fp1))
{
ch = fgetc(fp1);
if (ch != EOF)
fputc(ch, fp2);
}

fclose(fp1);
fclose(fp2);
}

#include<stdio.h>
#include<conio.h>
#include<stdlib.h>

void main()
{
system("copy e:\\学习.txt d:\\");
printf("OK");

getch();
}