Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
7 years, 11 months ago.
SD file name question
Hi,everyone. Thx for reading my question. i have a problem about SD file name. This is my SD data. Just like picture file name is file000. and My question is how to change my file name by time. i want file000 to be year date time. Example : file000 ->201612280947 I use LPC4088 board. And this is my code below.
#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; int main() { int n=0; char filename[64]; timer_w.start(); struct tm t; t.tm_sec = 37; // 0-59 t.tm_min = 47; // 0-59 t.tm_hour = 21; // 0-23 t.tm_mday = 28; // 1-31 t.tm_mon = 11; // 0-11 t.tm_year = 116; // year since 1900 time_t seconds = mktime(&t); set_time(seconds); mkdir("/sd/mydir", 0777); while(1){ if(timer_w.read() > 2){ sprintf(filename, "/sd/mydir/file%03d.txt",n); FILE *fp = fopen(filename, "a"); if(fp == NULL) { error("Could not open file for write\n"); } fprintf(fp,"%d\r\n",1); fclose(fp); n++; timer_w.reset(); } } }
Would someone can give me a hint how to do it? Thx very much!!!!