473,320 Members | 1,884 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

What is "\r" represent?

I check the ISO 9899 standard,

\r (carriage return) Movesthe active position to the initial position
of the current line.

What does it do? How to input?

I tried to use Flex to check this pattern as below:

%%
[a-zA-Z]\r printf( "Find a carriage return" );

I tried different input but it never matches.

What is the different of carriage return with the return on keyboard?
The RETURN we usually use is just a newline?
Mar 16 '07 #1
5 18449
In article <m2************@stu.ust.hk>,
Matthew Zhou <zh*********@gmail.comwrote:
>I check the ISO 9899 standard,
>\r (carriage return) Moves the active position to the initial position
of the current line.
>What does it do? How to input?
>I tried to use Flex to check this pattern as below:
>%%
[a-zA-Z]\r printf( "Find a carriage return" );
>I tried different input but it never matches.
>What is the different of carriage return with the return on keyboard?
The RETURN we usually use is just a newline?
The carriage return character might be used internally by the operating
system (possibly in conjunction with other characters) to indicate the
end of line for a text file. When you read such a file in (with the
same OS) as a text file, these internal line terminations are
automatically translated by the OS to appear to you as \n . If somehow
the text file managed to have a \r that is not part of the OS's line
termination sequence, then exactly what happens is up to the OS: some
of them might translate it to \n and some might leave it as a \r and
some might decide that there is an I/O error on the file.

In most OS's, you can write a stand-alone \r to a text file (one that
is not part of a line termination sequence) by simply coding '\r' as
the output character. You can't count on this coming through on input,
though, for the reasons mentioned above... and also because there are
OS's for which the carriage return character is the complete internal
line termination sequence, so writing a \r on those OS's might have the
same effect as writing \n .

If you were to take one of those text files and read it in as
a binary file, then the automatic translation of line terminators
does *not* take place -- binary files don't have line terminators
after all. So if you open a text file in binary mode, you might
be able to see the \r in input. (This can get to be
important for streams that are network sockets, as there
are many protocols such as SMTP in which the standard network
representation of a "line" includes a \r character that must be
silently gotten rid of.)

>\r (carriage return) Moves the active position to the initial position
of the current line.
>What does it do?
On input, \r is just another character, most often silently ignored
(except as noted above.)

The description you are looking at is the standard behaviour
of carriage return when one is output to a device such as a
terminal or human-viewable character display. The meaning of
carriage-return on input is less settled.
How to input?
Other than by writing one to a file and reading that file,
the method of inputing a carriage return at the keyboard is
OS (and user settings) dependant. Usually all of your
keyboard input is being interpreted by something -- e.g.,
something has to know that when you press left-shift and then
the z key, that you mean you want to input the 'Z' character
and not the two seperate keys <<left-shift>and 'z' . Often,
your input is not immediately sent to the program: instead,
your input usually gets buffered up, so that you can edit it
inline (e.g., backspace and press a new character) and only
the completed edited line gets sent. Such systems sometimes
offer no way of entering a carriage-return without it
meaning "newline"; sometimes there are methods such as
pressing control-M, or pressing \ followed by return,
or pressing control-V followed by return -- such methods are
not specified by C (you just might be able to dig such
a method out of POSIX's definition of the Bourne Shell).

--
"law -- it's a commodity"
-- Andrew Ryan (The Globe and Mail, 2005/11/26)
Mar 16 '07 #2
Matthew Zhou wrote:
I check the ISO 9899 standard,

\r (carriage return) Movesthe active position to the initial position
of the current line.

What does it do?
It moves the cursor or caret to the beginning of the current line. If
it's already at the beginning, the behaviour is unspecified.
How to input?
It's an output character.

<snip>
What is the different of carriage return with the return on keyboard?
The RETURN we usually use is just a newline?
A newline character is C's representation for the system's native
sequence for moving the active position to the start of the next line.
And yes, the Return, (or Enter), is setup to have this effect.

Mar 16 '07 #3
Matthew Zhou wrote, On 16/03/07 17:44:
I check the ISO 9899 standard,

\r (carriage return) Movesthe active position to the initial position
of the current line.

What does it do? How to input?
What do you not understand about "Moves the active position to the
initial position of the current line?" It seems self explanatory to me.
As to how to input it (I assume you mean from the keyboard) that depends
on your system.
I tried to use Flex to check this pattern as below:

%%
[a-zA-Z]\r printf( "Find a carriage return" );

I tried different input but it never matches.
Flex is off topic here.
What is the different of carriage return with the return on keyboard?
The RETURN we usually use is just a newline?
In C when a stream is opened in text mode whatever is used to indicate
and "end of line" which is what one would expect the return key to
produce, is translated to a newline. On DOS and Windows systems, this is
traditionally a carriage return followed by a new line.
--
Flash Gordon
Mar 16 '07 #4
Matthew Zhou wrote:
I check the ISO 9899 standard,

\r (carriage return) Movesthe active position to the initial position
of the current line.

What does it do?

Try this:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <time.h>

#define SIZE 4

void spin_wait(double secs)
{
clock_t start;
clock_t now;
double et;

if (secs <= 0)
return;
start = clock();
while (et < secs)
{
now = clock();
et = (double)(now-start)/CLOCKS_PER_SEC;
}
}

int main(void)
{
char star[SIZE] = "-\\|/";
int i;

while (1)
{
for(i = 0; i < SIZE; i++)
{
printf("\r%c ", star[i]);
fflush(stdout);
spin_wait(.25);
}
}

return 0;
}

Brian

Mar 16 '07 #5
On 16 Mar 2007 22:43:29 GMT, "Default User" <de***********@yahoo.com>
wrote:
>Matthew Zhou wrote:
>I check the ISO 9899 standard,

\r (carriage return) Movesthe active position to the initial position
of the current line.

What does it do?


Try this:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <time.h>

#define SIZE 4

void spin_wait(double secs)
{
clock_t start;
clock_t now;
double et;
Change that to:

double et = 0.0;
>
if (secs <= 0)
return;
start = clock();
while (et < secs)
{
now = clock();
et = (double)(now-start)/CLOCKS_PER_SEC;
}
}

int main(void)
{
char star[SIZE] = "-\\|/";
int i;

while (1)
I'd change that to:

for ( ; ; )

in order to avoid compiler and PC-lint warnings. YMMV.
{
for(i = 0; i < SIZE; i++)
{
printf("\r%c ", star[i]);
The first time through the loop, it performs a carriage return on a
non-existant line. Is that okay? I'm sure this is okay:

printf("%c\r", star[i]);
fflush(stdout);
spin_wait(.25);
}
}

return 0;
I'd change that to:

return 0; /*lint !e527: Unreachable code at token 'return'*/

YMMV.
}
Nice program (really), notwithstanding an uninitialized variable and
some arguably pedantic issues :)

--
jay
Mar 17 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

43
by: steve | last post by:
I am quite frustrated with php’s include, as I have spent a ton of time on it already... anyone can tell me why it was designed like this (or something I don’t get)? The path in include is...
2
by: steve | last post by:
Hi, I need to do conditional script "include", but like to pull the code from db instead of a file. How do I do that? Reason: I like to implement some complex regex logic, and make it table...
22
by: campbellbrian2001 | last post by:
Thanks in Advance! ... I have two textboxes: 1 is visible (and gets its value based on the invisible textbox and displays either "Male" or "Female", and needs to display either male of female based...
6
by: chandanlinster | last post by:
what do the values of "clocks_ticks = sysconf(_SC_CLK_TCK);" and "CLOCK_PER_SEC" represent?
8
by: Ulysse | last post by:
Hello, I need to clean the string like this : string = """ bonne mentalit&eacute; mec!:) \n <br>bon pour info moi je suis un serial posteur arceleur dictateur ^^* \n ...
2
by: Angus | last post by:
I am trying to change the selection in Javascript - but this HTML element is not a standard option control. On the web page it looks like a dropdown list - and you click on the right hand down...
5
by: Maria Sudderman | last post by:
I have a prblem with the "onClick" command. onClick="insert('<a href="URI">', '</a>')"> but this is not correct! why? Maria
1
by: manchin2 | last post by:
Hi, Can anybody please provide the information about "&quot" and its use, if possible please provide an example. ...
4
by: thaytu888888 | last post by:
Here is my codes in aspx page: <td colspan="2" class="main_menu" runat="server" onclick='toggleDisplay(<%#Eval("description")%>);'><%#Eval("description")%></td> Here is in "View source": ...
2
by: jmash | last post by:
Suppose I have the following string whch is part of an xml string: String s= "Script Id=&quot;Test&quot; " And I need to get s= "Script Id="Test" " Can anyone tell me how this can acheived? ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.