$(document).ready(function() { $('pre code').each(function(i, block) { hljs.highlightBlock(block); }); });

Sunday, July 11, 2010

Data copying program

#include
#include
void main()
{
char oldfname[50],newfname[50],x,ch;
FILE *fp1,*fp2;
clrscr();

printf("------------Program to copy data from one file to another------------");
printf("\nEnter the source/name of source file:");
gets(oldfname);
fp1=fopen(oldfname,"r");
if(fp1==NULL)
{
printf("\nSorry, No such files exist.The program will exit now.");
getch();
exit(0);
}
else
{
printf("\nEnter the name of destination file:");
gets(newfname);
fp2=fopen(newfname,"w");
while(!feof(fp1))
{
x=getc(fp1);
putc(x,fp2);
}
printf("\nData from '%s' has been copied to '%s'.",oldfname,newfname);
printf("\nDo you want to see it?(y/n):");
ch=getch();
printf("%c\n",ch);
if(ch=='Y'||ch=='y')
{
rewind(fp2);
while(!feof(fp2))
printf("%c",getc(fp2));
}
else
printf("\nOk, the program will exit now.");
}
getch();
}

No comments:

Post a Comment

Contact Me

Name

Email *

Message *