Thread: connected lists...???

  1. #1
    Registered User GiraffeMan's Avatar
    Join Date
    Feb 2002
    Posts
    20

    Unhappy connected lists...???

    hello ppl...
    i'm having a bit of a problem here...
    to cut a long story longer ... I was trying to make a program to handle cusotmer, product and order files.. but although it works kinda well, the connected structures I did (*next *prev), get filled with a lot of **** and it shows on the files...

    what to do???
    can anybody help me?
    I'm attachin the code here, please be patient about it it's long and annoying.....

    thanks in advanced....
    THE GIRAFFE MAN
    "our heads in the skies, but our feet on the ground"....

    http://dagan.150m.com

  2. #2
    the Corvetter
    Join Date
    Sep 2001
    Posts
    1,584
    You're right, it's long code. Can you show me where you think the problem's are? Just some pre-help tips, maybe you're not allocating the memory (a big problem with pointers and linked lists) and your system/compiler is taking some default values.
    1978 Silver Anniversary Corvette

  3. #3
    Registered User GiraffeMan's Avatar
    Join Date
    Feb 2002
    Posts
    20

    yes I know

    yes of course...
    I went through all the allocations and still didn't find what I was looking for... anyway I think the problem should be around this function (the one that sorts the data - read from file or input by user into the memory)...

    void add_customer(customer *q)
    {
    customer *p;
    if(q==NULL)
    {
    q=(customer*)malloc(sizeof(customer));
    get_customer_details(q);
    }
    if(q->exist!=1)
    {
    free(q);
    return;
    }
    if(cust_head==NULL)
    {
    cust_head=cust_tail=q;
    return;
    }
    else
    {
    if((q->id)<=(cust_head->id))
    {
    q->prev=NULL;
    q->next=cust_head;
    cust_head->prev=q;
    cust_head=q;
    return;
    }
    if((q->id)>=(cust_tail->id))
    {
    q->prev=cust_tail;
    cust_tail->next=q;
    q->next=NULL;
    cust_tail=q;
    return;
    }
    for(p=cust_head;p;p=p->next)
    if((p->id)>=(q->id)) break;
    p=p->prev;
    q->next=p->next;
    q->prev=p;
    p->next->prev=q;
    p->next=q;
    return;
    }
    }


    and here's another code that could be problematic:
    the function that writes it back to file:

    void writefile_cust()
    {
    FILE *cus;
    customer *d;
    if(cust_head==NULL) return;
    if((cus=fopen("customer.sdl","wb"))==NULL) { printf("can't write file"); getch(); return; }
    for(d=cust_head;d;d=d->next)
    if(d->exist==1)
    fwrite(d,sizeof(customer),1,cus);
    else d=d->next;
    fclose(cus);
    }


    thanks for looking at it anyway )
    THE GIRAFFE MAN
    "our heads in the skies, but our feet on the ground"....

    http://dagan.150m.com

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help creating lists of pointers
    By The_Kingpin in forum C Programming
    Replies: 2
    Last Post: 12-11-2004, 08:10 PM
  2. Question about Linked lists of lists
    By hear_no_evil in forum C Programming
    Replies: 2
    Last Post: 11-08-2004, 02:49 AM
  3. Linked Lists 101
    By The Brain in forum C++ Programming
    Replies: 5
    Last Post: 07-24-2004, 04:32 PM
  4. Map file formats and linked lists
    By Spitball in forum Game Programming
    Replies: 2
    Last Post: 03-04-2004, 11:32 PM
  5. need help w/ linked lists
    By MKashlev in forum C++ Programming
    Replies: 11
    Last Post: 08-05-2002, 08:57 PM