Path: utzoo!attcan!uunet!crdgw1!uakari.primate.wisc.edu!uflorida!mephisto!prism!prism.gatech.EDU!ce1zzes From: ce1zzes@prism.gatech.EDU (Eric Sheppard) Newsgroups: comp.lang.c Subject: Define a linked list of a linked list Message-ID: <13821@hydra.gatech.EDU> Date: 19 Sep 90 00:19:02 GMT Sender: ce1zzes@prism.gatech.EDU Organization: Georgia Institute of Technology Lines: 46 I've just given myself a crash course in C, to bring myself up to speed. My first project, a FORTRAN to C program conversion, was a resounding success. The resulting program uses linked structures for dynamic data input; no more hard-coded arrays! Makes the new program much more efficient and flexible. My next project is to convert another one of my old FORTRAN programs, but this one seems a bit more difficult. The problem: I'm not quite sure how to handle a linked list of a linked list. Structure : First member 4 char header, successive members 6 char data and 1 char flag. aaaa bbbbbb c bbbbbb c ... bbbbbb c Number of successive members must be variable; best way to implement this is with a linked list. I will be building a file of structures of the above format, and need to manipulate and organize them, preferably in memory; a kind of database. Depending on how efficiently the structures can be organized, I shouldn't have to worry about running out of memory (small-scale database running on mainframe). Since the total number of linked lists is not fixed, how can a linked list of the above linked list be defined? One idea: Place the header and next-structure-pointer into the outer list, and the successive members into the inner list. struct inner { char data[7]; char flag; struct inner *next; }; typedef struct inner INNR; typedef INNR *PT_INNR; struct outer { char header[5]; struct INNR; <- not sure about this declaration. Use pointer? struct outer *next; }; typedef struct outer OUTR; typedef OUTR *PT_OUTR; Are there any dangers involved with this setup? Advice would be appreciated... Eric, tinkerer-at-large