Thursday, 21 June 2012

write a program to copy the content of one file into another


/*write a program to copy the content of one file into another*/
#include<stdio.h>
#include<conio.h>
#include<process.h>
void main()
{
FILE *fs,*ft;
char ch;
fs=fopen("d:\peer.txt","r");
if(fs==NULL)
{
printf("cannot open source file");
exit(0);
}
ft=fopen("d:\peer1.txt","w");
if(ft==NULL)
{
printf("cannot open source file");
exit(0);
}
while(1)
{
ch=fgetc(fs);
if(ch==EOF)
break;
else
fputc(ch,ft);
}
fclose(fs);
fclose(ft);
getch();
}

No comments: