Click here to Skip to main content
Rate this: bad
good
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 at 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
0 OriginalGriff 304
1 Sergey Alexandrovich Kryukov 255
2 Shweta N Mishra 216
3 Maciej Los 210
4 PIEBALDconsult 174
0 OriginalGriff 7,660
1 Sergey Alexandrovich Kryukov 7,072
2 DamithSL 5,586
3 Manas Bhardwaj 4,946
4 Maciej Los 4,665


Advertise | Privacy | Mobile
Web04 | 2.8.1411023.1 | Last Updated 23 Mar 2013
Copyright © CodeProject, 1999-2014
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