Click here to Skip to main content
12,076,206 members (33,577 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C++
what is the basic functionality of \r? it will produce different results with executing in diff compilers like MinGW and linux?
Posted 23-Mar-13 7:57am
Edited 23-Mar-13 8:11am
v2
Comments
Volynsky Alex 23-Mar-13 13:48pm
   
http://msdn.microsoft.com/en-us/library/6aw8xdf2%28v=vs.80%29.aspx

Character: Carriage return
ASCII Representation: CR
ASCII Value : 13 or 0x0d
Escape Sequence : \r
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

It's not generally a compiler thing, it's an OS interpretation thing.
'\r' is a character called Carriage Return - because in the days of teletypes that is what it did, it moved the carriage (i.e. print head) to the left hand side of the paper.
Different system interpret what it does differently: some move the cursor to the far left, some move it to the left and down a line.

If you can, and you want to be portable, avoid using it directly - declare a constant instead so you cna change it if you need to.
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

Totally agree with the previous answer!

'\r' is the carriage return character.
The following repeats the loop until the user has pressed the Return key.
while(ch!='\r')
{
  ch=getche();
}
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web01 | 2.8.160208.1 | Last Updated 23 Mar 2013
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100