Re: tree example



On Mon, 1 Dec 2008 21:03:33 -0500, "Bill Cunningham"
<nospam@xxxxxxxxxxxxx> wrote:

Can anyone tell me what the (char *) is on page 143 kandr2 ? iinning to
understand the tree example but no what I just memtioned.

The only occurrence of the string "(char *)" in page 143 is a cast
applied to the return value of malloc. In the errata to K&R II, they
acknowledge that malloc and it siblings do not need this type of cast.
This code is a carry over from the pre-ANSI days when malloc returned
a char*.

This entire block of code is an implementation of the strdup function
which is used on page 141. Other than the fact that the addtree
function calls strdup, the function is not related to trees at all. It
merely copies the 'source' string (whose address is passed in an
argument) into a dynamically allocated block of memory.

--
Remove del for email
.



Relevant Pages

  • Re: using a tree to delete duplicate lines in a text
    ... int getline(FILE *fp, char *s, int lim) ... pointer to the node pointer where an item is found, ... I thought you purpose was to use someone else's tree code. ... If you want to store just strings, ...
    (comp.programming)
  • Re: Problems with (Cast)
    ... >> Why I'm getting this error when I try to cast as char? ... I wouldn't expect a single-character string to cast to ... > type of obj if it still doesn't work: ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Problems with (Cast)
    ... > Why I'm getting this error when I try to cast as char? ... I wouldn't expect a single-character string to cast to ... type of obj if it still doesn't work: ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Comment on trim string function please
    ... I've not been following why the cast is important; ... Serious bug. ... unsigned char. ... I appear to "getting" a signed 8-bit integer value from my string, ...
    (comp.lang.c)
  • Is a void * equivalent to a char *?
    ... Is the printfstatement correct? ... Or is a cast to char * required for vp? ... That is, assuming a void * is pointing to a string, what is the proper way ...
    (comp.lang.c)