Wednesday, November 12, 2008

File Copier


"
File copier" is a program to copy a file from one location to another using C.
Suppose you are copying a ".DAT" (video ) file from a scratched CD. If there is any error while reading , the data that is copied will also lose. But if you copy it with this the copied data will be remain in the destination. The number of errors present in the file will also displayed. This software will automatically correct many of the errors.

Download

The program code in turboc C as follows:



/* program to copy a file to another location
vipin.p.nair
s4 EC College of Engineering Kalooppara
20-march-2008
*/
#include "conio.h"
#include "stdio.h"

#include "io.h"
void main()
{
char name[100],folder[100],ch,temp=0;
long counterror=0,size=0;
FILE *f,*d;

textcolor(BLUE);
textbackground(WHITE);
clrscr();
textcolor(WHITE);
textbackground(LIGHTBLUE);
gotoxy(20,4);
cprintf(" File Copier ");
gotoxy(10,6);
cprintf(" vipin.p.nair S4-EC-CEK-2008 ");
gotoxy(1,8);
cprintf("************************************************************");
printf("\n\n\n\tEnter the file to copy : ");
gets(name);
if((f=fopen(name,"rb"))==NULL)
{
fprintf(stderr, "\tCan't open input file.\n");
getch();
return;
}
printf("\tEnter the path of the destinaton file name :");
gets(folder);

if((d=fopen(folder,"wb"))==NULL)
{
fprintf(stderr, "\tCan't create output file.\n");
getch();
return;
}

fseek(f,0L,SEEK_END);
size=ftell(f);
printf("\n\tSize : %ld bytes\n",size);

fseek(f, 0L, SEEK_SET);

textbackground(WHITE );
textcolor(BLUE);
gotoxy(1,20);
cprintf("please wait...");

while(!feof(f))
{

ch=getc(f);
if(ferror(f))
{
putc(temp,d);
counterror++;
continue;
}
putc(ch,d);
temp=ch;

}

if(!counterror)
printf("\n\tThe file was successfully copied.");
else
printf("\n\tThe file was copied"
"\n\tthe number of errors encounterd was %lf",counterror);
fclose(f);
fclose(d);

getch();
}

2 comments: