home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!sun-barr!olivea!spool.mu.edu!darwin.sura.net!gatech!rutgers!igor.rutgers.edu!remus.rutgers.edu!jjwright
- From: jjwright@remus.rutgers.edu ( Jay)
- Newsgroups: comp.lang.c
- Subject: HELP: structs and linked lists
- Message-ID: <Sep.14.11.11.48.1992.9598@remus.rutgers.edu>
- Date: 14 Sep 92 15:11:48 GMT
- Organization: Rutgers Univ., New Brunswick, N.J.
- Lines: 64
-
-
- greetings,
- i have a possible simple problem:
-
- i have a header file declaring some structs that are linked lists
-
- ex. struct grid { float area; struct grid *next;};
- struct ranges {int lat,lon;};
-
- i have a main program which defines/declares the head of the link list
-
- ex.
- struct grid head_list = {-1,NULL}, *head = &head_list;
- struct ranges range = {4,5};
-
- and i make this function call to build the linked list:
-
- err = make_list(&head_list,range);
-
- then in my subroutine (these are three seperate files):
-
- int make_list(struct grid *root,struct ranges range)
-
- i declare struct grid *trav = NULL;
-
- and i create a linked list:
-
- trav = root;
- in a look i do this:
- trav->area = 5.0;
- if ((trav->next = add_node(trav->next))==NULL) return -1;
- trav = trav->next;
-
- i have these two subroutines within this file:
- struct grid *add_node(struct grid *newone)
- which sets newone = t_alloc();
- and returns newone;
-
- and
- struct grid t_alloc(void)
- {
- return (struct grid *) malloc(sizeof(struct grid));
- }
-
- -------
-
- unfortunately my program is crashing as soon as it gets to the
- make_list call in the main program. when i try to run the debugger it
- doesnt tell me anything, instead i get a crash with the "stack
- collision with heap" error. (i only get that error if the debugger is
- on, otherwise the screen just freezes).
-
- am i doing all my structure pointers correctly, im new this? can i
- really be running out of room? i have very few declarations in the
- main program or in the make_list routine. In main i have about 8
- files open, but very few other variables, basically just a few
- integers.
-
- is there something that i am completely neglecting to do or
- overlooking?
-
- thanx.
-
- jay
-