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)

 

Parameters

Description

Handle

The value returned from FOpen()

String

String that should be written to a file

 

Code

 

 

void setup() {

 char STR1[] = "HelloWorld";

 

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

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

 CleO.FClose(f);

 

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

 CleO.FClose(f);

 

/* Display completed screen frame */

 CleO.Show();

}

 

void loop() {}

 

 

 

 

Description

 

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.

 

 

Output

 

Here is the output displayed upon executing the code snippet -

 

FPutS