Path: utzoo!utgpu!watmath!iuvax!purdue!haven!mimsy!chris From: chris@mimsy.UUCP (Chris Torek) Newsgroups: comp.unix.questions Subject: Re: Problems with ndbm Message-ID: <18933@mimsy.UUCP> Date: 7 Aug 89 18:02:59 GMT References: <34200002@zaphod> <34200003@zaphod> Organization: U of Maryland, Dept. of Computer Science, Coll. Pk., MD 20742 Lines: 42 In article <34200003@zaphod> doug@zaphod.prime.com writes: >What happens is something like: > > datum *x; > x = dbm_fetch(thedb, thekey); > x -> dptr[x -> dsize] = '\0'; > printf("%s\n", x -> dptr); // Something is printed > > x = dbm_fetch(thedb, thekey); > x -> dptr[x -> dsize] = '\0'; > printf("%s\n", x -> dptr); // Null is printed This code will not even compile without warnings, and is clearly not the code you used, since dbm_fetch returns a `datum' and not a `datum *'. At a guess, I would say the original code is rather more like this: datum getkey() { datum key; char buf[SOMESIZE]; key.dptr = buf; key.dsize = nnn; return (key); } ... thekey = getkey(); x = dbm_fetch(thedb, thekey); x.dptr[x.dsize] = '\0'; printf("%s\n", x.dptr); x = dbm_fetch(thedb, thekey); x.dptr[x.dsize] = '\0'; printf("%s\n", x.dptr); in which it is just chance that the *first* call worked; or else, the original code is something like this: thekey = dbm_fetch(thedb, otherkey); -- In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163) Domain: chris@mimsy.umd.edu Path: uunet!mimsy!chris