#include <stdio.h>
#include <stdlib.h>
/**
* Backup (copy) program for all file sizes
* @author Mohui
* @date 2015/04/10
*/
void Main ()
{FILE *sourcefile;
FILE *backupfile;
Char source[20],backup[20],ch;
printf ("Please enter the name of the source file:\n");
scanf ("%s", source);
printf ("\ n");
printf ("Please enter a name for the backup file:\n");
scanf ("%s", backup);
printf ("\ n");
if ((Sourcefile=fopen (source, "R")) ==null)
{
printf ("$ Error report:failed to open the source file!! \ n ");
Exit (0);
}
if ((Backupfile=fopen (Backup, "W")) ==null)
{
printf ("$ Error report:create a new file failed!! \ n ");
Exit (0);
}
do{
CH=FGETC (sourcefile);
FPUTC (Ch,backupfile);
FPUTC (ch,stdout); This line of code is used in the Run window preview to read the text content, in order to unnecessarily increase the display interface occupied, not recommended to write
}while (!feof (sourcefile));
Fclose (sourcefile);
Fclose (BackupFile);
printf ("\ n ... Backup successfully........\n\n ");
}
C language implementation of file read and write copy (book Improvement source version)