Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!dali.cs.montana.edu!caen!zaphod.mps.ohio-state.edu!pacific.mps.ohio-state.edu!linac!unixhub!stanford.edu!agate!agate!adrianho From: adrianho@barkley.berkeley.edu (Adrian J Ho) Newsgroups: comp.unix.programmer Subject: Re: NDBM and ME Message-ID: Date: 11 May 91 01:31:37 GMT References: Sender: root@agate.berkeley.edu (Charlie Root) Distribution: usa Organization: University of California, Berkeley Lines: 33 In-Reply-To: guest@geech.ai.mit.edu's message of 10 May 91 16: 49:44 GMT In article guest@geech.ai.mit.edu (Guest Account) writes: >I read the manual on ndbm but I still have a question. I want to >store structs and the structs have pointers to variable length >strings. If I store the struct using the data.dptr how will the >pointers remain valid after closing the database file? They don't -- you're screwed once your program terminates. > I don't really >care how I do it, I just want to be able to use some kind of database >management package on a struct like > struct system_entry { > char *system_name; > char *telephone_number; > char *login_name; > char *password; > } >I won't know how long the strings are at compile time. You don't have to -- just malloc() a string that's the total size of all 4 fields (plus 4 for their associated nulls), then use strcpy() to concatenate all 4 fields into the new string (be careful of the NULLs -- that's why I didn't say strcat()). You now have a single string with all 4 fields that can be used in an NDBM record. I'll leave the reverse process for you to figure out. Oh, and if you _must_ use a guest account for some reason, please leave a non-guest email address in your message, so that others can reply to you directly. Good luck!