Adding to file

15 Feb 2011

Is it possible to go to the end of a file and add some more data to it. I am planning a temperature logging project that would write the temperature to a file along with date and time. I would take temperature readings one per hour. I was thinking I could close the file and only open it when writing to it; once per hour. I have tried this with the localfilesystem and it overwrites the previous data. Is this possible to do with a SD card?

Torfinn Sørnes

16 Feb 2011

How are you opening the file? Typically if you open a file for append, you will get the behavior you want. For example:

FILE *fp = fopen("/local/test.txt", "a");

Hope that helps

16 Feb 2011

Thank you Adam it worked. The "a" did it. I tried with "w", and it overwrotes the previous data.

I misunderstood the following warning in the handbook. Thought I had to use fseek to go to the end of the file.

"fseek is not supported for files opened for writing ("w")"

Thanks again

Torfinn Sørnes