6 years, 9 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

6 years, 9 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

Accepted Answer

Thanks, Jennifer. I tried and found another solution. It seems that mbed connector web application does not send "newline" to the mbed client resource. I found another way to manually decode the input string with the new line.

posted by Masoud R. 10 Jun 2017