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)