|
From: Rafael C. <cha...@un...> - 2005-05-02 03:21:03
|
Per Westermark wrote:
>
> However, the above two alternatives may not be combined into:
> array[1] = malloc(strlen(sentence)+1);
> array[1] = "sentence";
> since the second assign will loose the reference to the memory previously
> allocated.
>
Per,
Thank you for remind us that!
Do you think it's safe using array[n]="string_literal" inside
functions?
<snip>
void foo (char *array[]){
array[0]="string_literal_1";
...
array[n]="string_literal_n";
}
</snip>
IMHO, for C code I'd use dynamic allocation with strings, since
it's not very common having only string literals. I mean, you don't
know exactly what you'll have, so you'll have to allocate memory.
Regards,
Rafael
--
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.308 / Virus Database: 266.11.0 - Release Date: 29/04/05
|