Friday, April 17, 2009

FILE COPY

#include
#include
void main()
{
FILE *fp1,*fp2;
char c;
int fpos;
clrscr();
fp1=fopen("d1.txt","w");

printf("write data and to stop press '.'FILE1:");
while(c!='.')
{
c=getche();
fputc(c,fp1);
}
fclose(fp1);
/*printf("\n contents read:");
fp1=fopen("d1.txt","r");
while(!feof(fp1))
{
printf("%c",getc(fp1));
}
fclose(fp1);*/
fp1=fopen("d1.txt","r");
fp2=fopen("d2.txt","a");

while(!feof(fp1))
{
c=fgetc(fp1);

fputc(c,fp2);
}
fclose(fp1);
fclose(fp2);

printf("\n contents read from file1 and file 2:");
fp2=fopen("d2.txt","r");
while(!feof(fp2))
printf("%c",getc(fp2));


fclose(fp2);
getch();
}

No comments: