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, 5 months ago.
write new-line to text file with sd-driver
Hi, I'm using sd-driver to write an input from mbed connector service PUT request to text file on sd card. I want to when I put a value like this: Hello\nWelcome\Bye stores as this on out.txt file: Hello Welcome Bye
I tried the following function but it as only to output.
include the mbed library with this snippet
void sd_open(string sd_value) { printf("Writing to Sd card..."); FILE* fd = fopen("/sd/out.txt", "w+"); fprintf(fd, "%s",sd_value.c_str()); fclose(fd); printf("writed this value to sd: %s\r\n", sd_value.c_str()); printf("Done\n"); }
I think I have to first find "\n" in sd_value then write the contents until "\n" then insert a newline separately with fprintf and then restart this procedure until end of the file. but I don't know how to implement this. If you know how to do it with this way or similar way, I would appreciate any help. Thanks
1 Answer
7 years, 5 months ago.
Hi Masoud,
Have you taken a look at the examples provided in the ARMmbed SD Driver github repository? The code inside of example1.cpp may help you with your own project.
- Jenny