ex_file_read.c

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

00001 included "fsee.h"
00002 
00008 void test(void) {
00009     FILE f;
00010     BYTE c;
00011     BYTE filename[12];
00012 
00013     //Initialize file system.
00014     fsysInit();
00015 
00016     //Copy the file name to the filename array. Terminating NULL is also copied
00017     strcpypgm2ram((char*)filename, (ROM char*)"myfile.txt"); 
00018     f = fileOpen(filename, 0);     //Open the given file
00019 
00020     if (f == FILE_INVALID )
00021     {
00022         //File not found, take action
00023     }
00024     else if ( f == FSYS_NOT_AVAILABLE )
00025     {
00026         //File System not available
00027     }
00028     else
00029     {
00030         while (1) {
00031             //Check if file has reached end
00032             if ( fileIsEOF(f) ) {
00033                 fileClose(f);
00034                 
00035                 //End of file, take whatever action is required ................
00036                 break;
00037             }
00038             
00039             //Read byte from file
00040             c = fileGetByte(f);
00041 
00042             //Check if error occured
00043             if ( fileHasError(f) ) {
00044                 fileClose(f);
00045                 
00046                 //Take action.............
00047                 break;
00048             }
00049         }
00050     }
00051 }

Generated on Thu Jul 5 21:26:30 2007 for SBC65EC Web Server by  doxygen 1.5.2