[2.0.3]-SDL_RWwrite() - How To Add End Of Line? |
JeZ-l-Lee
|
[2.0.3]-SDL_RWwrite() - How To Add End Of Line?
Hi, We just started learning SDL2's "File I/O Abstraction". http://wiki.libsdl.org/CategoryIO When using SDL_RWwrite(), how do we add end of line? We wish to write a line of data and then move to the next empty line to write then next. Let us know, thanks! |
|||||||||||
|
[2.0.3]-SDL_RWwrite() - How To Add End Of Line? |
Sik
|
Um, just write the relevant byte?
There are three different newline conventions: - 0x0D 0x0A (two bytes) - 0x0A (one byte) - 0x0D (one byte) Windows uses the first, most everything else uses the second, the third used to be what Mac had before OSX. Stick to one when writing and support all three when reading. If you want files to be readable with Notepad, use 0x0D 0x0A. _______________________________________________ SDL mailing list http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org |
|||||||||||
|
Re: [2.0.3]-SDL_RWwrite() - How To Add End Of Line? |
JeZ-l-Lee
|
Hi,
We tried this code:
It compiles ok, but crashes on execution (Win 8.1 64Bit)? |
|||||||||||||
|
JeZ-l-Lee
|
Ok, we got it working:
Thanks! |
|||||||||||||
|
[2.0.3]-SDL_RWwrite() - How To Add End Of Line? |
Sik
|
That will crash outside Windows...
Also you probably just want to stick to one of the conventions for writing (and support both when reading regardless of platform). 2015-05-07 2:34 GMT-03:00, JeZ-l-Lee:
SDL mailing list http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org |
|||||||||||||
|
[2.0.3]-SDL_RWwrite() - How To Add End Of Line? |
Eirik Byrkjeflot Anonsen
Guest
|
JeZ-l-Lee writes:
Umm, surely: const char* endOfLineForWindows = "\r\n"; const char* endOfLineForEverythingElse = "\n"; strcpy() expects to find a NUL byte at the end of the string it copies from, so if you use the array version, you would need: char endOfLineForWindows[3] = {'\r', '\n', 0}; And I'm pretty sure the non-_WIN32 version won't compile, as strcpy takes a "const char*" but you are feeding it a "char".
And if you use the "const char*" versions of endOfLineFor*, you might just do: const char * endOfLine; #ifdef _WIN32 endOfLine = endOfLineForWindows; #else endOfLine = endOfLineForEverythingElse; #endif eirik _______________________________________________ SDL mailing list http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org |
|||||||||||||||
|
JeZ-l-Lee
|
Hi,
Thanks to everyone... We got it working now on both Windows 8.1 Pro 64Bit & Linux(Linux Mint 17.1 KDE 64Bit). Thanks! |
|||||||||||
|
Naith
|
How did you solve it?
|
|||||||||||
|
JeZ-l-Lee
|
We will be releasing our SDL2 cross-platform game as open-source on this forum when it's done. Probably in about 2 weeks... Thanks! |
|||||||||||||
|