Thursday, 26 January 2012

Write a C program which copies one file to another.

#include<stdio.h>
#include<conio.h>
void main()
{
    FILE *fp, *fq ;
    char file1[20], file2[20];
    char ch;
    clrscr( );
    printf("Enter the source filename to be copied:");
    gets(file1);
    fp=fopen(file1,"r");
    if(fp==NULL)
    {
        printf("\nCannot open %s",file1);
        exit(0);
    }
    printf("\nEnter the destination filename:");
    gets(file2);
    fq=fopen(file2,"w");
    while((ch=getc(fp))!=EOF )
    {
        putc(ch,fq);
    }
    printf("\n Copied Sucessfully..");
    fclose(fp);
    fclose(fq);
    getch( );
}

No comments:

Post a Comment