M
MFO
Hi.. i don't knw is it a correct place to ask.. but i really need
help...
i have this backup code (below).. it successfully backup a file.. but
with this ÿ rubbish/bug at end of file.. so i don't know what cause it
appear.. any idea???
TQ
// Creates the backup file with extension .bak
//////////////////////////////////////////////
void CreateBackup (char filename[256])
{
char backup_filename [256]="";
char *ptr;
FILE *in, *out;
// to create backup file must take the filename
// without its extension and put .bak extension
strcpy (backup_filename,filename);
ptr=strtok(backup_filename,".");
strcat (ptr,".bak");
if ((in = fopen(filename, "rt"))
== NULL)
{
fprintf(stderr, "Cannot open input file.\n");
exit(1);
}
if ((out = fopen(backup_filename, "wt"))
== NULL)
{
fprintf(stderr, "Cannot open output file.\n");
exit(1);
}
while (!feof(in))
fputc(fgetc(in), out);
fflush(in);
fflush(out);
fclose(in);
fclose(out);
}
help...
i have this backup code (below).. it successfully backup a file.. but
with this ÿ rubbish/bug at end of file.. so i don't know what cause it
appear.. any idea???
TQ
// Creates the backup file with extension .bak
//////////////////////////////////////////////
void CreateBackup (char filename[256])
{
char backup_filename [256]="";
char *ptr;
FILE *in, *out;
// to create backup file must take the filename
// without its extension and put .bak extension
strcpy (backup_filename,filename);
ptr=strtok(backup_filename,".");
strcat (ptr,".bak");
if ((in = fopen(filename, "rt"))
== NULL)
{
fprintf(stderr, "Cannot open input file.\n");
exit(1);
}
if ((out = fopen(backup_filename, "wt"))
== NULL)
{
fprintf(stderr, "Cannot open output file.\n");
exit(1);
}
while (!feof(in))
fputc(fgetc(in), out);
fflush(in);
fflush(out);
fclose(in);
fclose(out);
}