Thursday 21 May 2015

Copy one file content to another file without using inbuilt functions

#include<stdio.h>
main()
{
FILE *f1,*f2;
char name[30],ch,dest[30];
clrscr();
printf("Enter a file name\n");
scanf("%s",name);
f1=fopen(name,"r");
if(f1==NULL)
{
printf("file not exists\n");
}else
{
printf("File exists\n");
printf("Enter dest file");
scanf("%s",dest);
f2=fopen(dest,"w");
while(!feof(f1))
{
ch=fgetc(f1);
if(ch!='\n' && ch!='\t' && ch!=' ')
{
printf("%c",ch);
fputc(ch,f2);
}

}
printf("file copied\n");

}
fclose(f1);
fclose(f2);
getch();

}

No comments:

Post a Comment