Help with tsearch (3C) in sysV
hxd9622 at ritcv.UUCP
hxd9622 at ritcv.UUCP
Fri Jul 18 17:53:49 AEST 1986
[]
I need help with some subroutines in sysV ie tsearch(3C) and tdelete(3C).
Does anyone know how to use these routines?
How do you pass the parameters?
I have declared the following struct...
struct rec
{
char *string;
struct rec *left, *right;
}
tsearch is declared as...
char *tsearch ((char *) key, (char **)rootp, compar)
int (*compar)();
I'm in a loop that reads a line of text and calls tsearch to insert
line in the tree...
while (fgets(line, MAXLINE, file))
ptr = (struct rec *)tsearch((char *)line, (char *)root, strcompar);
Note:
ptr should point to the node containing line in the binary tree.
root will point to new node if NULL.
strcompar SCfunction to compar 2 strings.
(char *)root == (char **)&root (isn't it?)
I don't understand the first argument to tsearch..
(char *)key - what is key?
is it the field contents - a string?
or is it a ptr to new node with new string in it?
I wrote my own routines for these but I need these routines for something
bigger. When I used my own routines, everything worked fine.
Can anyone help? Thanks a million!
PS
just in case Pnews doesn't ask for
my .signature...
-+-+-+-
Herman Darmawan @ Rochester Institute of Technology
UUCP {allegra,seismo}!rochester!ritcv!hxd9622
BITNET HND9622 at RITVAXC
... fight mail hunger ... mail me now!
#
More information about the Comp.unix.wizards
mailing list