title: Write string with newline to a text file c++
body: <p>First I don't know if my question already asked but I searched a lot and didn't find a straight forward answer to this question yet.
  I want to create a program to read a string wich has newlines <code>\n</code> in it and write the contents back to a text file on SD card with <code>fprintf()</code> function. My compiler is <code>ARM_GCC</code> and I'm using a specific library which only has <code>fprintf()</code> and <code>fwrite()</code> to write a string, so I preferred to only use these functions, but If you think there is another way I would appreciate if you say so.
  I can easily use this program to write a string to file:</p>
  
  <pre><code>void sd_open(string sd_value)
  {
    printf("Writing to Sd card...");
    FILE* fd = fopen("/sd/numbers.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");
  }
  </code></pre>
  
  <p>The problem is this code write the values of <code>sd_value</code> to one line only, I tought about using a for loop to search for newline in string and write line by line to a file but I dont know how to implement that.
  Thanks.</p>
  
  <p>EDIT...
  suppose that <code>sd_value</code> is something like this:</p>
  
  <pre><code>string sd_value="Hello\nWelcome\nBye"
  </code></pre>
  
  <p>which must be stored as the following to the text file:</p>
  
  <pre><code>Hello
  Welcome
  Bye
  </code></pre>
  
  <p>Actually, <code>sd_value</code> is not handling in my program and a user types a value in another application and I receive it as a string. I can tell the user to use \n in his text box to enter a newline but don't know how to treat it as a newline in my code.</p>