Jump to content
  • Advertisement
Sign in to follow this  
Lode

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

This topic is 2043 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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!

Share this post


Link to post
Share on other sites
Advertisement

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

Share this post


Link to post
Share on other sites

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.

Edited by mhagain

Share this post


Link to post
Share on other sites

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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

[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

Edited by L. Spiro

Share this post


Link to post
Share on other sites

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

 

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!