Subscribe

RSS Feed (xml)

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.

4 comments:

  1. so good.better to write algorithms,flow charts

    ReplyDelete
  2. best of luck.better to write algorithms,flow charts,remaining syllabus programs

    ReplyDelete
  3. can u plz explain this program step-wise and show the outfigure of output....plzzzzzzz

    ReplyDelete
  4. can u plz explain about fopen and fclose in short

    ReplyDelete