Re: Escape character treatment in string library functions
- From: "Malcolm McLean" <regniztar@xxxxxxxxxxxxxx>
- Date: Wed, 16 Jan 2008 15:03:12 -0000
<rejithomas.d@xxxxxxxxx> wrote in message news:83c99c40-9b92-441a-ba95-f6536ed4759c@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Can I change the escape character used by string libraries?. Mychar *doublebackslashes(char *in)
requirement is to
parse a string in format "domain\username" and change it into domain\
\username.
The C library functions takes \ as an escape character and also treat
'\r' etc special making it difficult to parse even char by char.
Can anyone suggest any solution to this issue
{
size_t count = 0;
size_t i = 0;
size_t j = 0;
char *answer = 0;
for(i=0;in[i];i++)
if(in[i] == '\\')
count++;
answer = malloc( strlen(in) + count + 1);
if(!answer)
return 0;
for(i=0;in[i];i++)
{
answer[j++] = in[i];
if(in[i] == '\\')
answer[j++] = '\\';
}
answer[j] = 0;
return answer;
}
int main(int argc, char **argv)
{
int i;
for(i=0;i<32;i++)
printf("%s\n", doublebackslashes("My\\Fred"));
return 0;
}
I've knocked up a little funcion for you.
I suspect that what you really need is a "make C escapes" however, which is a little more work.
--
Free games and programming goodies.
http://www.personal.leeds.ac.uk/~bgy1mm
.
- Follow-Ups:
- Re: Escape character treatment in string library functions
- From: rejithomas . d
- Re: Escape character treatment in string library functions
- References:
- 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: Easiest Programming Language For User Interactive Web Pages?
- 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
|