Mail Archives: djgpp/2005/07/07/08:31:16
Martin Ambuhl <mambuhl AT earthlink DOT net> wrote:
> > LD[i].LinePtr="";
> The second of these causes you to
> 1) lose the value returned by calloc
> 2) create a memory leak
> 3) assign LD[i].LinePtr to point to the string literal "",
and 4) evokes undefined behaviour in the next line, where he writes
something to LinePtr[0], i.e. tries to modify a string literal.
> *LD[i].LinePtr = 0;
That one's a bit gratuitously obfuscated.
LD[i].LinePtr[0] = '\0';
is almost certainly clearer to the OP.
Actually, the next line in the OP's source suggested that he actually
wants to do something like
strcpy(LD[i].LinePtr, "\n");
(he wrote a 13 in there, which is actually '\r', but you get the
picture...)
--
Hans-Bernhard Broeker (broeker AT physik DOT rwth-aachen DOT de)
Even if all the snow were burnt, ashes would remain.
- Raw text -