c语言编程高手进

来源:百度知道 编辑:UC知道 时间:2024/06/26 04:13:27
编写程序,实现复制file1文件成file2
高手进,做出来加分

c语言复制文件

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

int main(void)
{
FILE *in;
FILE *out;
char srcfile[256];
char destfile[256];
char ch;

printf("please input the source file:\n");
gets(srcfile);
printf("please input the dest file:\n");
gets(destfile);

if ((in = fopen(srcfile, "rb")) == NULL)
{
printf("fail to open %s\n", srcfile);
return 1;
}

if ((out = fopen(destfile, "wb")) == NULL)
{
printf("fail to open %s\n", destfile);
fclose(in);
return 1;
}

while(!feof(in))
{
ch = fgetc(in);
if (ch != EOF)
fputc(ch ,out);
}

fclose(in);
fclose(out);

}

#include <stdlib.h>
void main()
{
system("copy d:\\