home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / lang / c / 13635 < prev    next >
Encoding:
Internet Message Format  |  1992-09-14  |  2.0 KB

  1. Path: sparky!uunet!sun-barr!olivea!spool.mu.edu!darwin.sura.net!gatech!rutgers!igor.rutgers.edu!remus.rutgers.edu!jjwright
  2. From: jjwright@remus.rutgers.edu (   Jay)
  3. Newsgroups: comp.lang.c
  4. Subject: HELP: structs and linked lists
  5. Message-ID: <Sep.14.11.11.48.1992.9598@remus.rutgers.edu>
  6. Date: 14 Sep 92 15:11:48 GMT
  7. Organization: Rutgers Univ., New Brunswick, N.J.
  8. Lines: 64
  9.  
  10.  
  11. greetings,
  12. i have a possible simple problem:
  13.  
  14. i have a header file declaring some structs that are linked lists
  15.  
  16. ex.    struct grid { float area; struct grid *next;};
  17.     struct ranges {int lat,lon;};
  18.  
  19. i have a main program which defines/declares the head of the link list
  20.  
  21. ex.
  22.     struct grid head_list = {-1,NULL}, *head = &head_list;
  23.     struct ranges range = {4,5};
  24.  
  25.         and i make this function call to build the linked list:
  26.  
  27.         err = make_list(&head_list,range);
  28.  
  29. then in my subroutine (these are three seperate files):
  30.  
  31.     int make_list(struct grid *root,struct ranges range)
  32.     
  33.     i declare struct grid *trav = NULL;
  34.  
  35.     and i create a linked list:
  36.  
  37.     trav = root;
  38.     in a look i do this:
  39.     trav->area = 5.0;
  40.     if ((trav->next = add_node(trav->next))==NULL) return -1;
  41.     trav = trav->next;
  42.  
  43.     i have these two subroutines within this file:
  44.     struct grid *add_node(struct grid *newone)
  45.     which sets newone = t_alloc();
  46.     and returns newone;
  47.  
  48.     and
  49.     struct grid t_alloc(void)
  50.     {
  51.     return (struct grid *) malloc(sizeof(struct grid));
  52.     }
  53.  
  54. -------
  55.  
  56. unfortunately my program is crashing as soon as it gets to the
  57. make_list call in the main program.  when i try to run the debugger it
  58. doesnt tell me anything, instead i get a crash with the "stack
  59. collision with heap" error.  (i only get that error if the debugger is
  60. on, otherwise the screen just freezes).
  61.  
  62. am i doing all my structure pointers correctly, im new this?  can i
  63. really be running out of room?  i have very few declarations in the
  64. main program or in the make_list routine.  In main i have about 8
  65. files open, but very few other variables, basically just a few
  66. integers.
  67.  
  68. is there something that i am completely neglecting to do or
  69. overlooking?
  70.  
  71. thanx.
  72.  
  73. jay
  74.