C Language Development Kit/Functions/Fcopy

From OptiWiki

Jump to: navigation, search
Description This function copies an existing file to the specified location.
Syntax
void fcopy(const char * infile, const char * outfile);
Arguments
const char * infile
File name of the source file that needs to be copied.
const char * outfile
File name of the destination file to which the file needs to be copied.
Returns
0 File succesfully copied.
-1 Not enough space available on the destination drive.
-2 Specified source file not found.
-3 Error opening or creating destination file.
Remarks This function can be used to easily copy files from the SD drive to the RAM drive and back.
Example
#include <stdio.h>
#include <stdlib.h>
#include "lib.h"
 
void main( void )
{
    static char data[100+1];
    FILE *fp;
 
    while( 1 )
    {
        printf("\fExample of fcopy");
 
        if( (fp = fopen("C:TEST.DAT", "wb")) != NULL )
        {
            fwrite( data, 1, 100, fp);
            fclose(fp);
        printf("\nFile Created:\nC:TEST.DAT");
        }
 
        while( getchar() == EOF )
            idle();
 
        if( fcopy("C:TEST.DAT", "A:TEST.DAT") != 0 )
        {
            printf("\nCopying failed");
            continue;
        }
 
        if( fsize("C:TEST.DAT") == fsize("A:TEST.DAT") )
        {
            printf("\nCopied from:\nC:TEST.DAT");
            printf("\nCopied to:\nA:TEST.DAT");
        }
        else
            printf("\nCopying failed");
 
        while( getchar() == EOF )
            idle();
 
        remove("C:TEST.DAT");
    }
}


Views
Personal tools