On Tue, Jan 12, 2010 at 7:06 AM, John <[email protected]> wrote:
> --- In [email protected], John Gaughan <j...@...> wrote:
>>
>> Try initializing the memory to which newstr points before trying to use
>> it: this includes getting its length.
>
> 'getting' -> 'setting', or am I reading it wrong?

You're reading it wrong.

They're doing the equivalent of:

const char* str = "Hello world";
char* newstr = malloc(strlen(str));
printf("%d\n%d\n", strlen(str), strlen(newstr));

What is the contents of newstr at the printf() stage? (And,
incidentall,y why isn't it big enough to contain 'str'?)

Hint:
It's missing an equivalent  memcpy(newstr, str, strlen(str)) step.

-- 
PJH

http://shabbleland.myminicity.com/
http://www.chavgangs.com/register.php?referer=9375
http://www.kongregate.com/?referrer=Shabble

Reply via email to