Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utcs!mnetor!seismo!nbires!hao!hplabs!tektronix!uw-beaver!cornell!rochester!ritcv!hxd9622 From: hxd9622@ritcv.UUCP Newsgroups: net.unix-wizards Subject: Help with tsearch (3C) in sysV Message-ID: <9870@ritcv.UUCP> Date: Fri, 18-Jul-86 03:53:49 EDT Article-I.D.: ritcv.9870 Posted: Fri Jul 18 03:53:49 1986 Date-Received: Sun, 20-Jul-86 10:24:47 EDT References: <2321@brl-smoke.ARPA> Reply-To: hxd9622@ritcv.UUCP (Herman Darmawan) Organization: Rochester Institute of Technology, Rochester, NY Lines: 56 Keywords: sysV subroutines... Summary: How do you use tsearch, tdelete, twalk? [] 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@RITVAXC ... fight mail hunger ... mail me now! #