Re: String Character Conversion



On Fri, 30 Jun 2006 15:46:10 GMT, Jayson Davis
<eclecticboxers@xxxxxxxxx> wrote in comp.lang.c:



Say I have a string read from a configuration file.

searchfor <tab> Needle\n\n

Where I want to search for the word "Needle" with two linefeeds. Now
when I read it from the file, it hasn't converted the linefeeds into
characters. Is there a function to do that or do I need to write it myself?

Your question is not clear. What do you mean by "it"? What "it"
hasn't converted the linefeeds into characters? Everything you can
ever read from any file is composed of characters.

Do you mean that, on a single line read from a text file, you
literally have the four characters '\', 'n', '\', 'n' as the last four
text characters before the end of the line?

If that's what you mean, you will need to interpret the meaning in
your program. The mapping of escape sequences like \n, \t, \b, and so
on, in string literals and character constants, to single characters
is a feature of the compiler and performed when translating the source
code at compile time. There is nothing in the standard library that
does this translation for you at run time.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~ajo/docs/FAQ-acllc.html
.



Relevant Pages

  • Re: String Character Conversion
    ... Now when I read it from the file, it hasn't converted the linefeeds into characters. ... The string as read is "Needle\n\n", but what the string really needs to be is "Needle\x0A0\x0A" in order for strstror strcmpto work. ...
    (comp.lang.c)
  • Re: String Character Conversion
    ... Where I want to search for the word "Needle" with two linefeeds. ... The newline characters *are* characters, ... The string as read is "Needle\n\n", but what the string really needs to ...
    (comp.lang.c)
  • Re: String Character Conversion
    ... Say I have a string read from a configuration file. ... Where I want to search for the word "Needle" with two linefeeds. ... The newline characters *are* characters, ...
    (comp.lang.c)
  • Re: How to convert Infix notation to postfix notation
    ... If this is for an error message, why isn't it using stderr for its output? ... array of 15 characters, and you call this function with the limit 15 on ... Making sure that the only string I allocate and append to, ... because mulFactor in all versions must needs incorporate the functions ...
    (comp.lang.c)
  • Re: Prothon should not borrow Python strings!
    ... """It does not make sense to have a string without knowing what encoding ... same cul de sac as Python. ... Prothon_String_As_ASCII // raises error if there are high characters ... Python's split between byte strings and Unicode strings is ...
    (comp.lang.python)