The SDL forums have moved to discourse.libsdl.org.
This is just a read-only archive of the previous forums, to keep old links working.


SDL Forum Index
SDL
Simple Directmedia Layer Forums
[2.0.3]-SDL_RWwrite() - How To Add End Of Line?
JeZ-l-Lee


Joined: 20 Sep 2009
Posts: 572
Location: Long Island, New York, United States, Earth
[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


Joined: 26 Nov 2011
Posts: 905
Um, just write the relevant byte? Neutral

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


Joined: 20 Sep 2009
Posts: 572
Location: Long Island, New York, United States, Earth
Sik wrote:
- 0x0D 0x0A (two bytes)
- 0x0A (one byte)
- 0x0D (one byte)
Hi,

Thanks for the information.
How would I write "0x0D 0x0A" when using SDL_RWwrite() ?
I tried to use "\n" previously, but it did not work.

Thanks!
JeZ-l-Lee


Joined: 20 Sep 2009
Posts: 572
Location: Long Island, New York, United States, Earth
Hi,

We tried this code:
Code:
char endOfLine[3];
char *newLine;
char *carriageReturn;

sprintf(newLine, "%c", 0x0D);
sprintf(carriageReturn, "%c", 0x0A);

#ifdef _WIN32
    strcpy(endOfLine, newLine);
    strcat(endOfLine, carriageReturn);
#else
    strcpy(endOfLine, carriageReturn);
#endif

It compiles ok, but crashes on execution (Win 8.1 64Bit)?
JeZ-l-Lee


Joined: 20 Sep 2009
Posts: 572
Location: Long Island, New York, United States, Earth
Ok, we got it working:
Code:
char endOfLine[3];
char endOfLineForWindows[2] = {'\r','\n'};
char endOfLineForEverythingElse = '\n';

#ifdef _WIN32
    strcpy(endOfLine, endOfLineForWindows);
#else
    strcpy(endOfLine, endOfLineForEverythingElse);
#endif


Thanks!
[2.0.3]-SDL_RWwrite() - How To Add End Of Line?
Sik


Joined: 26 Nov 2011
Posts: 905
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:
Quote:
Ok, we got it working:

Code:
char endOfLine[3];
char endOfLineForWindows[2] = {'\r','\n'};
char endOfLineForEverythingElse = '\n';

#ifdef _WIN32
strcpy(endOfLine, endOfLineForWindows);
#else
strcpy(endOfLine, endOfLineForEverythingElse);
#endif



Thanks!

------------------------
JeZxLee
JessePalser <AT> GMail <DOT> com
16BitSoft Inc.
Video Game Design Studio
www.16BitSoft.com





_______________________________________________
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:

Quote:
Ok, we got it working:

Code:
char endOfLine[3];
char endOfLineForWindows[2] = {'\r','\n'};
char endOfLineForEverythingElse = '\n';

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".


Quote:
#ifdef _WIN32
strcpy(endOfLine, endOfLineForWindows);
#else
strcpy(endOfLine, endOfLineForEverythingElse);
#endif


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


Joined: 20 Sep 2009
Posts: 572
Location: Long Island, New York, United States, Earth
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


Joined: 03 Jul 2014
Posts: 158
How did you solve it?
JeZ-l-Lee


Joined: 20 Sep 2009
Posts: 572
Location: Long Island, New York, United States, Earth
Naith wrote:
How did you solve it?
Hi,

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!