FY_BCA_C_SLIP 5_2



slip 5_2. Copy the content of one file into another file



#include<stdio.h>
void  main( )
{
FILE *fp1,*fp2;

            char f1[20],char f2[20],ch;

printf("\n Enter first file name ");
scanf("%s",f1);
 
if( (fp1=fopen(f1,"r") ) = = NULL)
{
           printf("\n First file can not open ");
           exit(0);
}

printf("\n Enter 2nd file name ");
scanf("%s",f2);
fp2=fopen(f2,"w");

while(1)
{
ch = fgetc(fp1);
if(ch = = EOF)
break;
else fputc(ch,fp2);
}
       

fclose(fp1);
fclose(fp2);
           getch();
}

No comments:

Post a Comment