Skip to main content
GameDev.net gamedev.net
🔒 Locked

What is the value of '\n' in Windows?

Started by Lode May 7, 2013 at 4:36 PM 6 replies 2.3k views
Original Post
Lode
Lode

Hello,

Since Windows uses two characters for a newline (13 and 10), what is the value of the C++ character '\n' in Windows? 13 or 10?

I don't have a Windows machine nearby to test it on, hence the question.

Thanks!

SimonForsman
SimonForsman

Hello,

Since Windows uses two characters for a newline (13 and 10), what is the value of the C++ character '\n' in Windows? 13 or 10?

I don't have a Windows machine nearby to test it on, hence the question.

Thanks!

ascii \n = 10 , \r = 13
[size="1"]I don't suffer from insanity, I'm enjoying every minute of it.
The voices in my head may not be real, but they have some good ideas!
21st Century Moose
21st Century Moose

0x0a, or 10 - same as elsewhere. Newlines are handled by the C/C++ runtime so that you don't have to worry about that.

An interesting historical note is here: http://blogs.msdn.com/b/oldnewthing/archive/2004/03/18/91899.aspx

The unix ancestry of the C language carried this convention into the C language standard, which requires only "\n" (which encodes LF) to terminate lines, putting the burden on the runtime libraries to convert raw file data into logical lines.

Direct3D has need of instancing, but we do not. We have plenty of glVertexAttrib calls. 
Lode
Lode

Thanks!

I'm also wondering about the following:

When using getchar(), and you type some text followed by "enter", then this "enter", too, gets output by getchar.

In Unix systems, this will be a final value of 10.

In Windows, should I expect there to be both a 10 and a 13, or only a 10? In other words, if I type "a" followed by enter in the terminal, will getchar() return something three times in Windows, or only 2 times?

Digivance
Digivance
Lode, you many times will receive 10 followed by 13 as if it where two separate keystrokes. Personally I normally counter act this in cros platform apps by simply ignoring the character 10 or \r. Haven't found many if any reasons to use character 10 outside of windows.
L. Spiro
L. Spiro

[EDIT]
I could have sworn he said he skipped the \n, not the \r… dry.png
[/EDIT]

[EDIT2]

He did say he skipped \n (0xA or character 10). Hence my confusion.

Dan Mayor you should correct your post to avoid confusion. \r = 0x0D (13) and \a = 0x0A (10).

[/EDIT2]


L. Spiro

I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid
Endemoniada
Endemoniada

You can always do this:



char c='\n';
 
char out[8];
sprintf(out,"%d",c);
// output it somehow
// or just do a breakpoint and look at c

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.