Writing to LocalFileSystem

19 Jun 2012

Hi, I'm really new to MBED and I have to make a program that writes data to local file every hour. Currently testing it out with 2 secs interval. I want the program to write into the same .txt file everytime. However, everytime it writes into localfile, it overwrites the current file, thus losing all previous data. Is there a way to make it write into the same file and not overwrite it? My code looks something like this:

LocalFileSystem local("local");

void DoSleep(void *) { WFE(); }

void AlarmFn(void *) {

FILE *fp = fopen("/local/DayGen.txt", "w"); fprintf(fp, "Testing..."); fclose(fp); }

int main() {

AlarmTimeDate::Init(); AlarmTimeDate a1(AlarmFn,NULL,seconds+2);

do { FILE *fp = fopen("/local/DayGen.txt", "w"); fprintf(fp, "Hello World!!"); fclose(fp);

AlarmTimeDate::PrintAlarms(); AlarmTimeDate::Tick(DoSleep,NULL); seconds+=2; a1.Set(seconds); } while(1); }

19 Jun 2012

You see the W? put A instead as you want to apend to the file and not overwrite the same file?

atleast thats what i think it may be :\

19 Jun 2012

I managed to get the output to "Testing...Hello World!!" and that's it.

I need the output to be like: Testing... Hello World!! Hello World!! Hello World!!

so on and so forth.

Is my coding completely wrong to begin with, or do I just need to change something somewhere? Using a LPC1768 MBED btw

19 Jun 2012

Could you post your updated code? Don't forget to use the <<code>> and <</code>> tags before and after your program (each on their own line) to make it display properly.

Wirhout the tags it is too difficult to to tell if you are making some mistake in your use of Alarm..., etc.

19 Jun 2012

Chai Su Tian wrote:

I managed to get the output to "Testing...Hello World!!" and that's it.

I need the output to be like: Testing... Hello World!! Hello World!! Hello World!!

so on and so forth.

Is my coding completely wrong to begin with, or do I just need to change something somewhere? Using a LPC1768 MBED btw

For a new line always do "sometexthere\r\n" at the end of your strings this will allow you to print a line then print down

Hello world

Hello world

ect

Can you show me your code?

< < code >> code here < < / code > >

Without spaces?

20 Jun 2012

Oh so thats how you post codes here!

I added the \r and the program totally works now, thanks!!!!!

20 Jun 2012

Chai Su Tian wrote:

Oh so thats how you post codes here!

I added the \r and the program totally works now, thanks!!!!!

Your welcome :)

By the way, this page will come in handy, especially the table of contents half way down for character constants. http://msdn.microsoft.com/en-us/library/6aw8xdf2.aspx