BRT Community

Please login or register.

Login with username, password and session length
Advanced search  

News:

Welcome to the Bridgetek Community!

Please read our Welcome Note

Technical Support enquires
please contact the team
@ Bridgetek Support

Please refer to our website for detailed information on all our products - Bridgetek - Bridging Technology

Author Topic: CleO file write append to new line  (Read 20486 times)

Chris/

  • Newbie
  • *
  • Posts: 6
    • View Profile
CleO file write append to new line
« on: December 10, 2018, 03:54:20 PM »

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: [Select]
#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() {}

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
Logged

Chris/

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: CleO file write append to new line
« Reply #1 on: December 13, 2018, 08:08:43 AM »

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: [Select]
#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() {}
Logged

BRT Community

  • Administrator
  • Hero Member
  • *****
  • Posts: 771
    • View Profile
Re: CleO file write append to new line
« Reply #2 on: January 22, 2019, 02:26:57 PM »

Hello,

Thanks for you solution!

Best Regards,
BRT Community
Logged