CBFalconer <cbfalconer@yahoo.com> writes:
> magix wrote:
>>
>> I have
>> char* str1 = "d:\temp\data\test.txt"
>>
>> I want to replace all the "\" to be "\\", so that
>> the string will have "d:\\temp\\data\\test.txt"
>>
>> Can you ?
>
> No. str1 is a non-writable string. You can create str2 and copy
> str1, with modifications, into it. The copy part will look
> something like:
>
> while (*p1) {
> if ('\' == (*p2++ = *p1++)) *p2++ = '\';
> }
Note that '\' is a syntax error. It should be '\\'.
--
Keith Thompson (The_Other_Keith)
kst-u@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"