f. Read Characters - FGetC()

<< Click to Display Table of Contents >>

Navigation:  Tutorials > Tutorial 17 - CleO File System >

f. Read Characters - FGetC()

The FGetC() command is used to read a character from the file.



Command Prototype


uint16_t FGetC(int16_t Handle)






The value returned from FOpen()






void setup() {

 int g;

 uint8_t buf[3];

 char data[10];


/* Initialize CleO - needs to be done only once */



/* Start building a screen frame */



 CleO.StringExt(FONT_MEDIUM, 160, 100, LIGHT_GREEN, TM, 0, 0,

 "Seeking ball.png...");



 for (size_t i = 0; i < 4; i++) {


/* Open file in read mode */

   g = CleO.FOpen("@Pictures/ball.png", FILE_READ);


 /* Seek at ith position */

   CleO.FSeek(g, i);


  /* Read a character from seek position */

  buf[i] = CleO.FGetC(g);


  /* Close file */




 sprintf(data, "%x %x %x", buf[0], buf[1], buf[2]);


 /* Display collected data */

 CleO.StringExt(FONT_MEDIUM, 160, 200, LIGHT_GREEN, TM, 0, 0, "Data from file:");

 CleO.StringExt(FONT_MEDIUM, 160, 300, LIGHT_GREEN, TM, 0, 0, data);


 /* Display completed screen frame */




void loop() {}





In the above code snippet, the code highlighted in yellow color shows how the characters are read from the file using the FGetC() command. The for loop is used to seek each character in the file and stores it in the buffer. After reading each character, the file is closed and the data collected is displayed. Use the @ symbol only when performing the file operation from the eFlash and not from the SD Card.





Here is the output displayed upon executing the code snippet -