Re: can I split a C string
- From: "Bartc" <bc@xxxxxxxxxx>
- Date: Tue, 08 Jul 2008 10:19:59 GMT
"Richard Heathfield" <rjh@xxxxxxxxxxxxxxx> wrote in message
news:NPydncrGj7D_v-7VRVnyugA@xxxxxxxxx
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.)
If you're talking about the ASR33, this I think /required/ the two
characters, CR to move the head to the left, and LF to advance a line. They
were two different operations.
For convenience, whenever the user pressed Return, it was echoed back as CR
LF.
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.
I think Windows itself didn't help by requiring both CR and LF to be present
when sending text to the console, just like the teletype, otherwise lines
would either overwrite themselves (LF missing), or newlines would start
halfway across the screen (CR missing). So it was advisable to keep the CRLF
ending in a text file.
On Jul 7, 10:13 pm, Keith Thompson <ks...@xxxxxxx> wrote:
If that's meant
to be a Windows-style line ending, then (a) it's "\r\n", not "\n\r",
In text mode these will result in CR CR LF or CR LF CR, even more waste. And
if sent to a file, a lot of confusion for programs that expect specific line
endings.
--
Bartc
.
- Follow-Ups:
- Re: can I split a C string
- From: Richard Heathfield
- 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
- Re: can I split a C string
- From: Richard Heathfield
- can I split a C string
- Prev by Date: Re: is a pointer memset to zero necessarily eqal to NULL?
- Next by Date: Re: read and write columns
- Previous by thread: Re: can I split a C string
- Next by thread: Re: can I split a C string
- Index(es):
Relevant Pages
|