ex_file_read.c

This example code will read a file from the File System.

included "fsee.h"

void test(void) {
    FILE f;
    BYTE c;
    BYTE filename[12];

    //Initialize file system.
    fsysInit();

    //Copy the file name to the filename array. Terminating NULL is also copied
    strcpypgm2ram((char*)filename, (ROM char*)"myfile.txt"); 
    f = fileOpen(filename, 0);     //Open the given file

    if (f == FILE_INVALID )
    {
        //File not found, take action
    }
    else if ( f == FSYS_NOT_AVAILABLE )
    {
        //File System not available
    }
    else
    {
        while (1) {
            //Check if file has reached end
            if ( fileIsEOF(f) ) {
                fileClose(f);
                
                //End of file, take whatever action is required ................
                break;
            }
            
            //Read byte from file
            c = fileGetByte(f);

            //Check if error occured
            if ( fileHasError(f) ) {
                fileClose(f);
                
                //Take action.............
                break;
            }
        }
    }
}

Generated on Wed Feb 3 12:45:33 2010 for SBC65EC Web Server by  doxygen 1.5.8