k. Write String - FPutS()

<< Click to Display Table of Contents >>

Navigation:  Tutorials > Tutorial 17 - CleO File System >

k. Write String - FPutS()

The FPutS() command is used for writing a string to a file.



Command Prototype


uint16_t FPutS(int16_t Handle, const char* String)





The value returned from FOpen()


String that should be written to a file





void setup() {

 char STR1[] = "HelloWorld";


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



/* Start building a screen frame */



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

                 "Creating TestPutS.txt...");

  /* open file for write */

  int16_t f = CleO.FOpen("@TestPutS.txt", FILE_CREATE_ALWAYS | FILE_WRITE);


CleO.StringExt(FONT_MEDIUM, 160, 180, LIGHT_GREEN, TM, 0, 0, "Writing HelloWorld...");


  /* write one string into file */

  CleO.FPutS(f, STR1);

/* close file using file handle */



/* Open to read back */

 char buf[30] = {0};

 int16_t actual;

 f = CleO.FOpen("@TestPutS.txt", FILE_READ);

 CleO.FRead(f, (uint8_t *)buf, 10, actual);

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

                "Read back: ");

 CleO.StringExt(FONT_MEDIUM, 160, 340, LIGHT_GREEN, TM, 0, 0, buf);

/* close file using file handle */



/* Display completed screen frame */




void loop() {}







The above code snippet opens the test.txt file in write mode. The code highlighted in yellow color shows how the FPutS() command writes the string to the file and displays it accordingly. Once the process is completed, the file is closed using the FClose() command. 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 -