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

[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!------------------------
JeZxLee
JessePalser <AT> GMail <DOT> com
16BitSoft Inc.
Video Game Design Studio
www.16BitSoft.com

Um, just write the relevant byte? :expressionless:

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.

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!------------------------
JeZxLee
JessePalser <AT> GMail <DOT> com
16BitSoft Inc.
Video Game Design Studio
www.16BitSoft.com

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)?------------------------
JeZxLee
JessePalser <AT> GMail <DOT> com
16BitSoft Inc.
Video Game Design Studio
www.16BitSoft.com

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

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

JeZ-l-Lee writes:

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

#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

Hi,

Thanks to everyone…
We got it working now on both Windows 8.1 Pro 64Bit & Linux(Linux Mint 17.1 KDE 64Bit).

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

How did you solve it?

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!------------------------
JeZxLee
JessePalser <AT> GMail <DOT> com
16BitSoft Inc.
Video Game Design Studio
www.16BitSoft.com