Monday, January 19, 2009

Write a C program which copies one file to another.

#include(stdio.h) // place this '<' & '>' instead of '(' & ')' before stdio.h
#include(conio.h)
int 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( );
return 0;
}

Note:- If u have any doubt regarding this program or logic, please feel free to contact me.

No comments:

Post a Comment