Re: can I split a C string
- From: Richard Heathfield <rjh@xxxxxxxxxxxxxxx>
- Date: Tue, 08 Jul 2008 08:21:15 +0000
KIRAN said:
On Jul 7, 10:13 pm, Keith Thompson <ks...@xxxxxxx> wrote:
KIRAN <kira...@xxxxxxxxx> writes:
can i split a C string like this?
char * p = "Hello \
World\n\r";
is this according to standard?
In addition to the answers you've gotten (yes, you can, but there's a
much better way), why does your string end in "\n\r"?
Actually I am writing portable code that runs on windows & ARM9 .
my print function will print
1. (WINDOWS)the string on console window(here "\r" is not
required(correct me if am wrong)
2. (ARM) the string on hyperterminal(UART)
If that's meant
to be a Windows-style line ending, then (a) it's "\r\n", not "\n\r",
and
Why?
Because there was a teletype device in the 1960s on which moving the
carriage (the thing that carried the print head) from the right edge of
the paper to the left edge took twice as long as it took for a character
to arrive over the wire. To avoid dropping characters during the return of
the carriage from right to left, the designers split the task into two -
returning the carriage to the left edge of the paper, and feeding the
paper up a line - so that it would require two input characters to do this
one task, and thus the carriage would have time to do its thing without
any characters being dropped. (Essentially, the linefeed started life as a
padding character.)
CP/M uncritically adopted the CR/LF convention, wasting one byte per line
of text file. Recognising this, the Unix guys dropped the CR, whereas the
Mac folks dropped the LF. 86-DOS (QDOS) inherited the pair from CP/M, and
then was rebadged as MS-DOS, which was later rebadged as Windows. So even
in 2008, Windows users are stuck with this two-character newline encoding
several decades after the obsolescence of the hardware whose shortcomings
it was introduced to work around.
--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
.
- Follow-Ups:
- Re: can I split a C string
- From: Antoninus Twink
- Re: can I split a C string
- From: Bartc
- Re: can I split a C string
- References:
- can I split a C string
- From: KIRAN
- Re: can I split a C string
- From: Keith Thompson
- Re: can I split a C string
- From: KIRAN
- can I split a C string
- Prev by Date: Re: Problem 77: Greedy Gift Givers
- Next by Date: Re: How to convert character
- Previous by thread: Re: can I split a C string
- Next by thread: Re: can I split a C string
- Index(es):
Relevant Pages
|