Pages: [1]   Go Down
Author Topic: How to write newline to sdfile?  (Read 571 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Jr. Member
**
Karma: 0
Posts: 50
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi all,

i try to write sensor values to a line in a SD file, i use sdfatlib. It works OK.
But: i want to write a newline ("\n") every 5000 characters.

I thought of doing:

Code:
if (str.length() > 5000){
   sdfile.print("\n");
}

but it does not work very well. Which character should i use?
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 631
Posts: 50123
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
but it does not work very well. Which character should i use?
Ah, the famous "that didn't work" statement.

That code does something. You expect(ed) it to do something. What either thing is is not clear.

As a hint, though, the class you are using most likely derives from the Print class, this has both print() and println() methods. The println() methods do know how to place a carriage return AND line feed in the file.

Your call is adding one, but not the other, which, to some applications, makes a difference.
Logged

Leeds, UK
Offline Offline
Edison Member
*
Karma: 80
Posts: 1729
Once the magic blue smoke is released, it won't go back in!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

If say you were using Windows, and say Notepad to view the files, you would need to declare the Carriage Return character aswell as windows uses <CR><LF> to move to a new line. You could try sdfile.print("\r\n").
Logged

~Tom~

Pages: [1]   Go Up
Jump to: