home *** CD-ROM | disk | FTP | other *** search
- /* This is a short program demonstrating the fcopy function. It
- prompts the user for source and target filenames and then performs
- the copy. If an error occurred during the copy operation, an error
- message is displayed.
-
- Written by Ray Waters */
-
- #include <io.h>
- #include <stdio.h>
- #include <string.h>
- #include <errno.h>
- #include "fcopy.h"
-
- main()
- {
- char SrcName[80]; /* buffer for source filename */
- char DestName[80]; /* buffer for target filename */
- int input;
-
- printf("\nDemonstration of fcopy function:\n");
-
- do {
- printf("\n Enter the source file name: ");
- gets(SrcName); /* get source filename */
-
- input = access(SrcName, 0); /* see if source exists */
- if (input)
- perror("\nINPUT ERROR"); /* if not, display error */
- }
- while (input); /* and try again */
- strupr(SrcName); /* fold to upper case */
-
- printf("\n Enter the target file name: ");
- gets(DestName); /* get target filename */
- strupr(DestName); /* fold to upper case */
-
- if (!_fcopy(SrcName, DestName)) { /* perform the file copy */
- /* if successful, */
- printf("\nSUCCESS: Copied %s to %s\n", SrcName, DestName);
- return 0; /* exit */
- }
-
- switch (errno) { /* on error, display appropriate message */
- case -1:
- fprintf(stderr, "\nFCOPY ERROR: Target disk full\n");
- break;
- default: /* message depends upon errno */
- perror("\nFCOPY ERROR");
- break;
- }
- if (!remove(DestName)) /* try to delete bad target file */
- printf("Target file %s deleted\n", DestName);
-
- return -1; /* exit */
- }
-