l. Write Character

<< Click to Display Table of Contents >>

Navigation:  Tutorials > Tutorial 17 - CleO File System >

l. Write Character

The FPutC() command is used for writing a character into a file.

 

 

Command Prototype

 

uint16_t FPutC(int16_t Handle, int16_t Character)

 

Parameters

Description

Handle

The value returned from FOpen()

Character

The character to be written to a file

 

Code

 

 

void setup() {

 char STR1[10] = {'H', 'e', 'l', 'l', 'o', 'W', 'o', 'r', 'l', 'd'};

 

 /* 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 TestPutC.txt...");

/* open file for write */

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

 

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

                "Writing HelloWorld...");

               

/* write each character into file */

  for (int i = 0; i < 10; i++) {

    CleO.FPutC(f, STR1[i]);

  }

/* close file using file handle */

 CleO.FClose(f);

 

/* Open to read back */

 char buf[30] = {0};

 int16_t actual;

 f = CleO.FOpen("@TestPutC.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 FPutC() command writes the character into 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 -

 

FPutC