Linked List problems !

This is a discussion on Linked List problems ! within the C Programming forums, part of the General Programming Boards category; Hi, These two functions just try to accept some input then store it on a linked list...no errors..but when it ...

  1. #1
    Unregistered
    Guest

    Linked List problems !

    Hi,
    These two functions just try to accept some input then store it on a linked list...no errors..but when it runs..the whole thing just crashed! why???


    -----------------------------------------------------------------------------------void enter(void)
    {
    struct address *info;
    for(;
    {
    info=(struct address *)malloc(sizeof (list_entry));
    if(!info)
    {
    printf("\nout of memory");
    return;
    }
    printf("Enter a string:",info ->name,30);
    if(!info->name [0])break;
    dls_store (info, &start, &last);
    }
    }


    ----------------------------------------------------------------------------------
    void dls_store(struct address *i, struct address **start, struct
    address **last)

    {
    struct address *old, *p;
    if (*last==NULL)
    {
    i->next=NULL;
    i->prior=NULL;
    *last=i;
    *start=i;
    return;
    }

    p=*start; //start at the top of list

    old=NULL;
    while (p)
    {
    if (strcmp(p->name,i->name)<0)
    {
    old=p;
    p=p->next;
    }
    else
    {
    if(p->prior)
    {
    p->prior->next=i;
    i->next=p;
    i->prior=p->prior;
    p->prior=i;
    return;
    }
    i->next=p; //new first element
    i->prior=NULL;
    p->prior=i;
    *start=i;
    return;
    }
    }
    old->next=i;
    i->next=NULL;
    i->prior=old;
    *last=i;
    }

    ----------------------------------------------------------------------------------

  2. #2
    Unregistered
    Guest
    p.s that for (loop in the first function

    for (;..then a smiling face suppose to be another ; = for (;; )

  3. #3
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Hi,
    These two functions just try to accept some input then store it on a linked list...no errors..but when it runs..the whole thing just crashed! why???
    Gee, that's really helpful. Post only PART of your code, and expect use to fix it, with us having no idea WHERE in the program it crashes. "the whole thing just crashes" tells me nothing of where it's crashing at. Do you get any text on the screen yet? Do you get to enter text? Is it displaying the list? What exactly?

    printf("Enter a string:",info ->name,30);
    What exactly is this line supposed to do?


    Quzah.
    Hope is the first step on the road to disappointment.

  4. #4
    Unregistered
    Guest

    Talking

    hehehe..thanks quzah..u just might have found the problem...

    that line..suppose to be

    inputs("enter a string:",info->name,30);

    Okay..m sorry I didnt make it clear, yes the program does run, the menu is up, but when i choose the "enter a string" option which call up that function, it crashes...! ok??

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Linked List Help!
    By mbk in forum C Programming
    Replies: 3
    Last Post: 01-31-2008, 02:54 PM
  2. singly linked to doubly linked
    By jsbeckton in forum C Programming
    Replies: 10
    Last Post: 11-06-2005, 06:47 PM
  3. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 10:03 AM
  4. Problem with linked list ADT and incomplete structure
    By prawntoast in forum C Programming
    Replies: 1
    Last Post: 04-30-2005, 01:29 AM
  5. Linked List Help
    By CJ7Mudrover in forum C Programming
    Replies: 9
    Last Post: 03-10-2004, 09:33 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21