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)

 

 

Parameters

Description

Handle

The value returned from FOpen()

 

 

Code

 

 

void setup() {

 int g;

 uint8_t buf[3];

 char data[10];

 

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

 CleO.begin();

 

/* Start building a screen frame */

 CleO.Start();

 

 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 */

   CleO.FClose(g);

 }

 

 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 */

 CleO.Show();

}

 

void loop() {}

 

 

Description

 

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.

 

Output

 

Here is the output displayed upon executing the code snippet -

 

FGetC