7 years, 4 months ago.

Seperate many txt file in SD

Hi everyone~ Thx~ And i want to ask a question about Seperate many txt file in SD. Now i do is this picture. /media/uploads/david8251/sd1.png All data are in the same txt. But what i want is "one value with one txt". Example: sdtest1 has only "1" value .Next "1" will with stdtest2 ...... This is my code. Would someone can give me some point to solve this problem?

#include "mbed.h"
#include "SDFileSystem.h"

SDFileSystem sd(p5, p6, p7, p8, "sd"); // the pinout on the mbed Cool Components workshop board
Timer timer_w;
Timer timer_s;

int main() { 
    timer_w.start();
    timer_s.start();
    
    mkdir("/sd/mydir", 0777);
    mkdir("/sd/mydir123", 0777);
    while(1){
        if(timer_w.read() > 2){        
            FILE *fp = fopen("/sd/mydir/sdtest.txt", "a");
            if(fp == NULL) {
                error("Could not open file for write\n");
            }
            fprintf(fp,"%d\r\n",1);
            fclose(fp); 
            timer_w.reset();
        }
    }
}

Thx very much!

1 Answer

7 years, 4 months ago.

I don't know what you like to do, forever generating variable filenames can be done with the snprintf function, check the "snprintf man page" on Linux or via Google.

Accepted Answer

It's OK. i just solve my problem by myself XDDDDD THX!!!

posted by jajn HA 28 Dec 2016