string a = "abcdef";
aa[80] = a.c_str();
>
bb[40] = how can I get def from aa in here?
>
thanks
a.c_str() + 4
But you should know, that result of c_str() method is valid only till
the first change in `a'. So you should make copy of i if you need
C-string and cannot guarantee, that no change in `a' will occure.
Did you actually try this? If you got the purported results, then it
was by sheer bad luck. You didn't terminate the string, and strncpy
doesn't do it for you. Outputting the result was undefined behavior.
Default User wrote in message <4s1h4hFtbh0qU1 @mid.individual .net>...
>BobR wrote:
>
<snip **incomplete** func1>
>// out: frst=abc last=def
>
>Did you actually try this?
Yes.
If you got the purported results, then it
>was by sheer bad luck. You didn't terminate the string, and strncpy
>doesn't do it for you. Outputting the result was undefined behavior.
Of course you are correct. My bad. (gads, I hate that phrase!!).
Thanks for the 'heads-up'.
<?>
It must have been that the char arrays were initialized to zeros by my
compiler.
<checking.... >
Nope!!! Just happened to be a zero at 4th position in both arrays.
[....even on re-compiles. ....and adding another array before those.]
[ I can't seem to break it! ]
</?>
Murphy's "bad luck" clause strikes again!!
Thanks again for the correction.
--
Bob R
POVrookie
Comment