delete

This is a discussion on delete within the C Programming forums, part of the General Programming Boards category; this delete function suppose delete a character stored in linked list. but it gives me error on buffer=buffer->cursor->next; code. Code: ...

  1. #1
    Registered User
    Join Date
    Sep 2002
    Posts
    32

    delete

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


    Code:
    void DeleteCharacter(bufferT buffer)
    {
    	position ptemp;
    
    	
    	ptemp = buffer -> head;
    
    	while(ptemp!= buffer->cursor)
    	{
    		buffer = buffer -> cursor ->next;
    	}
    	ptemp = buffer;
    	free(buffer);
    }
    here are definitions
    Code:
    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
    Posts
    14,826
    You should be checking for NULL. Additionally, how is your list set up? I'm assuming you've got:

    node->next->next->next->next

    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:
    Code:
    position ptr;
    
    ptr = buffer->cursor;
    while( ptr != NULL && ptr != tofind )
        ptr = ptr->next;
    Vola!

    Quzah.
    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, 05: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, 10:17 PM
  5. Problem need help
    By Srpurdy in forum C++ Programming
    Replies: 1
    Last Post: 07-24-2002, 12:45 PM

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