Re: can I split a C string



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
.



Relevant Pages

  • Re: How many bytes per Italian character?
    ... yes I know how to ask Windows CE how big a buffer I'm going to need. ... and characters in Italian are the same size as characters in English, ... So have you detected that WinCE will cause a buffer overrun? ... It is not an error to tell you a string might be longer than it actually ...
    (microsoft.public.vc.mfc)
  • Re: How many bytes per Italian character?
    ... In a general case where I don't know the expected length of the string, yes I know how to ask Windows CE how big a buffer I'm going to need. ... In some cases I might still verify the type that comes back to see if it's really a string or not, but in the general case I know how to inspect the retorted result to find out what type it's registered as today. ... correlation between characters and code points. ...
    (microsoft.public.vc.mfc)
  • Re: Joining 2 strings
    ... > posted above overwrite the 3 lines, ... "carriage return, line feed". ... Now, if you print that string to the screen, Windows prints "abcdefghi", ...
    (comp.lang.perl.misc)
  • Re: After being send through socket string is corrupted
    ... unix text file in windows notepad and you will see a square character ... > that only contains a string to a server. ... > it contains the correct text but additionally there are strange characters ...
    (comp.lang.java.programmer)
  • Re: can I split a C string
    ... Actually I am writing portable code that runs on windows & ARM9. ... the string on console window(here "\r" is not ... the carriage from right to left, the designers split the task into two - ... paper up a line - so that it would require two input characters to do this ...
    (comp.lang.c)