Re: Escape character treatment in string library functions
- From: Logan Shaw <lshaw-usenet@xxxxxxxxxxxxx>
- Date: Wed, 16 Jan 2008 22:44:30 -0600
rejithomas.d@xxxxxxxxx wrote:
Thanks everyone for the reply. But the issue I am facing is
I get a string literal in the format "domain\username" (with a single
\ and not \\ ,. say char *str= "dom\ret") .If I try to parse the
string char by char C treats '\r' as a single character.
It isn't accurate to say that when you are doing things character
by character that C is treating "\r" as a single character. There
are two reasons why this isn't accurate:
(1) When you are doing the character by character processing,
there is no C. There is only a binary. The binary was
produced by a C compiler, but that is immaterial at that
point.
(2) When you are doing the character by character processing,
there is no sequence of characters "\" followed by "r".
There is only a carriage return, which is a single character.
Nothing is treating anything as a single character. There
is no special processing going on. There just is a single
character.
For eg:
char *str="dom\ret";
while( *(str++) !='\0')
if(*str == '\\' )
printf("found");
is not working since it sees '\r' as a single char .
If you don't want C to produce a string constant with a
carriage return in it, then don't tell the C compiler to
produce a string constant with a carriage return in it.
If you want a string constant with a "\" character followed
by a "r", then write this: "\\r". Then the "\\" will be
translated into a "\" when the source code is turned into
a string constant.
- Logan
.
- References:
- Escape character treatment in string library functions
- From: rejithomas . d
- Re: Escape character treatment in string library functions
- From: Malcolm McLean
- Re: Escape character treatment in string library functions
- From: rejithomas . d
- Escape character treatment in string library functions
- Prev by Date: Re: Escape character treatment in string library functions
- Next by Date: Re: Herbert Schildt, author of The Complete C++ Reference (NOT C Unleashed) rehabilitated on wikipedia
- Previous by thread: Re: Escape character treatment in string library functions
- Next by thread: Re: Escape character treatment in string library functions
- Index(es):
Relevant Pages
|