On Fri, 27 Jun 2003 19:30:34 +0200, Oodini wrote:
>>>char *script;
>>>script = scalloc(71,sizeof(char));
>
>
>> assuming calloc(), you have initialized this pointer with the value returned
>> by calloc() which is the address of a freshly allocated block. All bits are
>> set to zero. Note that sizeof(char) is 1 by-definition. How did you specify
>> 71? Isn't it a better way of doing it? I mean automagically (strlen, sizeof
>> etc.)
>
> Please don't laugh: I counted them. 
> To use strlen, I have to create a string.
strlen("I am a string literal. I can be used in strlen") works.
Also,
const char *foo = "I am a string literal.";
strlen(foo);
works.
> But my goal was to create a pointer to free it later.
> Not really needed (a string would be OK).
> But may I free a string ?? I don't think so...
Nope, but there's no reason to. Your memory usage increases if you
manually allocate somewhere to put a copy - string literals are never
freed.
>
>> The value passed to free() must be exactly the one you got from malloc() (or
>> one of its brothers). You have changed it, creating a memory leak, hence the
>> undefined behaviour.
>
> OK. i got it now. Thanks.
--
Freenet distribution not available
There's no saint like a reformed sinner.