Wednesday, July 20, 2011

Program to copy one file to another file

/*Serial No.90     [swami65.cpp]*/

#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
void main()
{
int i;
char ch,name[10];
clrscr();
FILE *fp1,*fp2;
fp1=fopen("swami1.dat","r");
if(fp1==NULL)
    {
    printf("file doesn't exist");
    getch();
    fclose(fp1);
    exit;
    }
fp2=fopen("swami2.dat","w");
if(fp2==NULL)
    {
    printf("file doesn't exist");
    getch();
    fclose(fp2);
    exit;
    }

printf("file is being copied.\n");
while(1)
    {
    ch=fgetc(fp1);
    if(ch==EOF)
    break;
    else
    fputc(ch,fp2);
    }
fclose(fp1);
fclose(fp2);
getch();
}

No comments:

Post a Comment

If you have any doubt, feel free to ask...