Problem writing more than one kine to SD card

25 Nov 2011

I am trying to build a logger, this is a first trial with SD card. I can't figure out what is wrong with this very simple code. When I comment the loop, it writes one line to a card without problem. If I use the for loop, the file is created but stays empty; I have the same problem with USB memory. However it works on local file system.

Any idea?

 #include "mbed.h"
 #include "string"
 #include "SDHCFileSystem.h"
 
 //LocalFileSystem fs("sd");
 SDFileSystem sd(p5, p6, p7, p8, "sd"); // mosi, miso, sclk, cs
 
 int main() {
       
      FILE *fp = fopen("/sd/my2file.txt", "w");
      for(int i = 0; i < 1000; i++){
        fprintf(fp, "Hello World! \n");
        wait(0.1);
      }
       fclose(fp);
 }
25 Nov 2011

Never mind, the problem was obvious and solved by writing "a" instead of "w". FILE *fp = fopen("/sd/my2file.txt", "a");