Does structure order matter?



Hello, I've been quite comfortable using linked list for a while now
without much hassle, but lately I've been getting problems from unexpected
places. I'm working on a graphing utility program, and to allow multiple
functions to be entered I figured the best way would be with a linked list:

struct List{
int color; /*The color it will be when drawn*/
int index; /*It's index: Y1, Y2, etc...*/
char Y[76]; /*The function itself*/
struct List *prev;
struct List *next;
}*current,*first,*hold,*last;

And I use a switch to process user input...
(Last is the last node before NULL and hold is a general placeholder)

switch(r){
case INSERT: /*When the Insert key is pressed*/
/*Do some graphics related stuff*/
/*Add a node to the end of the list*/
last->next=malloc(sizeof(struct List));
if(last->next==NULL){
puts("Cannot allocate function memory.");
exit(1);
}
hold=last;
last=last->next;
last->prev=hold;
last->next=NULL;
last->color=hold->color+1;
last->index=hold->index+1;
/*More graphics stuff*/
ggets(last->Y,76); /*<-My own string input function*/
/*More graphics stuff*/
break;

>From the above, I get errors. Running through the list is fine from first
to last but from last to first it points to garbage. But I noticed
everything seems to run fine if I put the:

last->prev=hold;
last->next=NULL;

after the ggets() statement. It's really confusing me as to why. Or is this
a different problem entirely that I may have overlooked?
I greatly appreciate any input.

Brian Dude
.



Relevant Pages

  • Re: General computer use
    ... >America and plan to take my computer with me - will it work there or will it ... >be more hassle than it's worth? ... (and most have a switch for that), it should be no trouble at all. ...
    (microsoft.public.windowsxp.general)
  • Re: Using enums to avoid using switch/if
    ... additional hassle that you might forget that you needed an index. ... more than glorified assembly-language programming with the additional ... My point was that in the given example, replacing if ladders with switch would buy little in terms of bloat, and that taking advantage of enums is more likely to. ...
    (comp.lang.java.programmer)
  • Re: HP printers are they worth the money?
    ... Epson does at switch on, so it's not a real big hassle just a minor one. ... Prev by Date: ...
    (comp.periphs.printers)
  • Re: LLC ownership of airplane -- another twist
    ... anything really for you other than add another layer of hassle. ... Corps. ... help out with multiple people involved in the aircraft but ...
    (rec.aviation.owning)
  • Re: Backup software
    ... multiple people on it. ... But unless you're dead broke, ... Makes for slightly more hassle, but safer. ...
    (comp.sys.mac.system)