General Category > Discussion - Cleo

CleO file write append to new line

(1/1)

Chris/:
Hi,

I'm trying to append some information to a new line within the same .txt file using the CleO file system however i seem to just be overwriting the same line each time.


--- Code: ---#include <SPI.h>
#include <CleO.h>

void setup() {
  char STR1[] = "ABCDEFG";
  char STR2[] = "HHHHHHH";
  char STR3[] = "IIIIIII";
  int16_t actual;

  CleO.begin();

  int16_t f = CleO.FOpen("test.txt", FILE_OPEN_EXISTING | FILE_WRITE);
  CleO.FWrite(f, strlen(STR1) + 1, (uint8_t*)STR1, actual);
  CleO.FClose(f);

  CleO.FOpen("test.txt", FILE_OPEN_EXISTING | FILE_WRITE);
  CleO.FWrite(f, strlen(STR2) + 1, (uint8_t*)STR2, actual);
  CleO.FClose(f);

  CleO.FOpen("test.txt", FILE_OPEN_EXISTING | FILE_WRITE);
  CleO.FWrite(f, strlen(STR3) + 1, (uint8_t*)STR3, actual);
  CleO.FClose(f);
}

void loop() {}

--- End code ---

I'm after a file that gives:

  ABCDEFG
  HHHHHHH
  IIIIIII

but the code above gives:

IIIIIII

Is there a way of achieving what I'm after?

thanks,

Chris

Chris/:
I guess i should have read through the filing system tutorials better!

Here's a solution to this saving it into a .csv file:


--- Code: ---#include <SPI.h>
#include <CleO.h>


char STR1[] = "A,B,C,D,E,F,G\n";
char STR2[] = "H,H,H,H,H,H,H\n";
char STR3[] = "I,I,I,I,I,I,I\n";
int16_t actual;
int16_t f;
uint32_t pointer = 0;


void setup() {
 
  CleO.begin();
 
  f = CleO.FOpen("test.csv", FILE_OPEN_ALWAYS | FILE_WRITE);
  while (!CleO.FEOF(f)) {                                      // Moves pointer position through the file until end of file is found
    CleO.FSeek(f, pointer);
    pointer++;
  }
  CleO.FWrite(f, strlen(STR1) + 1, (uint8_t*)STR1, actual);
  CleO.FClose(f);

  CleO.FOpen("test.csv", FILE_OPEN_ALWAYS | FILE_WRITE);
  while (!CleO.FEOF(f)) {
    CleO.FSeek(f, pointer);
    pointer++;
  }
  CleO.FWrite(f, strlen(STR2) + 1, (uint8_t*)STR2, actual);
  CleO.FClose(f);
 
  CleO.FOpen("test.csv", FILE_OPEN_ALWAYS | FILE_WRITE);
  while (!CleO.FEOF(f)) {
    CleO.FSeek(f, pointer);
    pointer++;
  }
  CleO.FWrite(f, strlen(STR3) + 1, (uint8_t*)STR3, actual);
  CleO.FClose(f);


}

void loop() {}
--- End code ---

BRT Community:
Hello,

Thanks for you solution!

Best Regards,
BRT Community

Navigation

[0] Message Index

Go to full version