Thread: delete

  1. #1
    Registered User
    Join Date
    Sep 2002


    this delete function suppose delete a character stored in linked list. but it gives me error on buffer=buffer->cursor->next; code.

    void DeleteCharacter(bufferT buffer)
    	position ptemp;
    	ptemp = buffer -> head;
    	while(ptemp!= buffer->cursor)
    		buffer = buffer -> cursor ->next;
    	ptemp = buffer;
    here are definitions
    typedef struct node{
       char data;
       struct node *link;
       struct node *prev;
       struct node *next;
    }  node;
    typedef struct node *position;
    typedef struct bufferType{
       node *head;
       node *cursor;
       node *clipboard;
    } bufferType;

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    You should be checking for NULL. Additionally, how is your list set up? I'm assuming you've got:


    Given a node 'n', it has a double linked list 'c'. To thread 'c' correctly, you really should be doing:

    ptr = n->c;
    while( ptr != NULL && ptr != tofind )
    ptr = ptr->next;

    See, you're getting yours confused. Not every 'node' has a 'cursor'. 'cursor' is an element of 'bufferType', not of 'node'.

    That's where you're getting confused.
    You need a temporary 'node' pointer, as I've done above, and then you assign it like:
    position ptr;
    ptr = buffer->cursor;
    while( ptr != NULL && ptr != tofind )
        ptr = ptr->next;

    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Proper Usage of the delete Operator
    By thetinman in forum C++ Programming
    Replies: 7
    Last Post: 04-25-2007, 11:53 PM
  2. BST delete again, but this time I think I'm close
    By tms43 in forum C++ Programming
    Replies: 9
    Last Post: 11-05-2006, 06:24 PM
  3. delete and delete []
    By Lionel in forum C++ Programming
    Replies: 8
    Last Post: 05-19-2005, 01:52 PM
  4. why is this prog crashing on delete?
    By Waldo2k2 in forum Windows Programming
    Replies: 2
    Last Post: 12-04-2002, 11:17 PM
  5. Problem need help
    By Srpurdy in forum C++ Programming
    Replies: 1
    Last Post: 07-24-2002, 12:45 PM