e. Seek File - FSeek()

<< Click to Display Table of Contents >>

Navigation:  Tutorials > Tutorial 17 - CleO File System >

e. Seek File - FSeek()

The FSeek() command is used to move the file read/write pointer of an open file object.



Command Prototype


uint16_t FSeek(int16_t Handle, uint32_t Offset);





The value returned from FOpen()


File pointer location to seek






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 file seek operation is performed using the FSeek() command. The for loop is used to look for each character in the file and store 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 -