fopen "rw"

08 Jul 2009 . Edited: 01 Sep 2009

This code is causing me trouble. Supposedly, one of "rw" or "r+" should allow both reading and writing to a file. However, I can't get either to work. The code below ought to print "Writable and now readable" to out.txt, but only prints "Writable".

#include "mbed.h"

LocalFileSystem local("local");

int main()
{
	FILE *fp = fopen("/local/out.txt", "w");
	fprintf(fp,"Writable");
	fclose(fp);
	
	fp = fopen("/local/out.txt", "rw");	\\or "r+"
	fprintf(fp,"and now readable");
	fclose(fp);
}

Any advice?

10 Jul 2009

off the top of my head...

(and it really is off the top of my head).. but I'm sure google may help...

I had a play with such a thing recently..

is it "a" rather than "rw" for readwrite access ?

10 Jul 2009

a+ ?

 

11 Jul 2009

"a" is for append, meaning I have to write to the end of the file. Unfortunately, I need the ability to write to a certaion point in the file. I think "a+" is for append and read. Neither are really suitable for the job.

However, it is apparently "w+" or "r+". "rw" is supposedly meaningless. Neither work though. Looking at some ARM documentation, it is hinted at that read/write files are not implemented.