关于文件复制问题代码
// l10_1.2.cpp : Defines the entry point for the console application.//
#include "stdafx.h"
#include<conio.h>
#include<stdlib.h>
#include<string.h>
#define SIZE 10
int _tmain(int argc, _TCHAR* argv[])
{
FILE*fp;
char ch1[SIZE];
char ch2[SIZE];
char ch3[SIZE];
printf("请输入三个字符串:\n");
gets(ch1);
gets(ch2);
gets(ch3);
if((fp=fopen("string.txt","w"))==NULL)
{
printf("Cannot open file strike any key exit!");
exit(-1);
}
fputs(ch1,fp);
fputs(ch2,fp);
fputs(ch3,fp);
fclose(fp);
char ch4[SIZE*3]={0};
if((fp=fopen("string.txt","r"))!=NULL)
{
fgets(ch4,SIZE*3,fp);
printf("您输入的字符串为:");
puts(ch4);
fclose(fp);
}
char ch5[SIZE*3];
if((fp=fopen("string2.txt","w"))==NULL)
{
printf("Cannot open file strike any key exit!");
exit(-1);
}
strcpy(ch5,ch4);
fputs(ch5,fp);
fclose(fp);
if((fp=fopen("string2.txt","r"))==NULL)
{
printf("Cannot open file strike any key exit!");
exit(-1);
}
fgets(ch5,SIZE*3,fp);
fclose(fp);
_getch();
return 0;
}
红色的字体是复制已有的文件内容