Code Competitions

Coding competition

Monday, 13 May 2013

Program to copy content of one file to another

#include<stdio.h>
#include<conio.h>
void main()
{
    FILE *fp1,*fp2;
    char ch;
    clrscr();
    fp1=fopen("te1.txt","w");
    while((ch=getchar())!='*')
    {
        putc(ch,fp1);
    }
    fclose(fp1);
    fp2=fopen("te2.txt","w");
    fp1=fopen("te1.txt","r");
    while((ch=getc(fp1))!=EOF)
    {
        putc(ch,fp2);
    }
    fclose(fp1);
    fclose(fp2);
    fp2=fopen("te2.txt","r");
    while((ch=getc(fp2))!=EOF)
    {
        printf("%c",ch);
    }
    fclose(fp2);
    getch();
}

No comments:

Post a Comment