Thread: another pointers

  1. #1
    Registered User
    Join Date
    Aug 2001
    Posts
    380

    another pointers

    Pointer to structure required on left side of -> or ->*

    I get this error throughout the code. What changes do I make?

    Code:
    void updateBullet(struct bulletList** headRef)
    {
    	struct bulletList** current = headRef;
    	if(current == NULL)
    		puts("Bullet List is empty");
    
    	while(current != NULL)
    	{
    
    		current->y--; // like here
    		if(current->y < 0) // and here
    			deleteBullet(&current,current->x,current->y);
    
    		current = current->next; // and here
    	}
    
    }
    Don't you dare hit me on the head, you know I'm not normal.
    A Stooge Site
    Green Frog Software

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >current->y--; // like here
    current isn't a pointer to a structure where this syntax would be correct, it's a pointer to a pointer to a structure, you have to dereference the first pointer and then use the arrow notation to get access to a member:
    Code:
    (*current)->y--;
    My best code is written with the delete key.

  3. #3
    Registered User
    Join Date
    Aug 2001
    Posts
    380
    Does current = current->next become (*current) = (*current)->next?
    Don't you dare hit me on the head, you know I'm not normal.
    A Stooge Site
    Green Frog Software

  4. #4
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >Does current = current->next become (*current) = (*current)->next?
    Have you tried it? If so, does it do what you want?
    My best code is written with the delete key.

  5. #5
    Registered User
    Join Date
    Aug 2001
    Posts
    380
    No it doesn't and after I have replaced all current's with the correct current the program crashes.
    Don't you dare hit me on the head, you know I'm not normal.
    A Stooge Site
    Green Frog Software

  6. #6
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    When working with pointers to pointers you must be sure to dereference the outer pointer first, then do what you need to do:
    Code:
    void dothing(struct thing **head)
    {
      struct thing **current = head;
    
      /* If the list is empty */
      if (*current == NULL)
        return;
      /* While not at the end */
      while (*current != NULL) {
        printf("%s", (*current)->s);
        /* Go to the next one */
        *current = (*current)->next;
      }
    }
    If you're doing all of this correctly, your problem likely lies in the deleteBullet function and how you're calling it.
    My best code is written with the delete key.

  7. #7
    Registered User
    Join Date
    Aug 2001
    Posts
    380
    For some reason now after changing it to look similar to your example code the list is getting lost. Maybe including the source will all you to provide better help.

    Thank you for your help so far.
    Don't you dare hit me on the head, you know I'm not normal.
    A Stooge Site
    Green Frog Software

  8. #8
    Me want cookie! Monster's Avatar
    Join Date
    Dec 2001
    Posts
    680
    Code:
    void updateBullet(struct bulletList** headRef)
    {
    	struct bulletList** current = headRef;
    	if(current == NULL)
    		puts("Bullet List is empty");
    
    	while(*current != NULL)
    	{
    
    		(*current)->y--;
    //		if((*current)->y < 0)
    //			deleteBullet(&(*current),(*current)->x,(*current)->y);
    
    		*current = (*current)->next;
    	}
    
    }

  9. #9
    Registered User
    Join Date
    Aug 2001
    Posts
    380
    I'm still losing the list after those changes.
    Don't you dare hit me on the head, you know I'm not normal.
    A Stooge Site
    Green Frog Software

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Using pointers to pointers
    By steve1_rm in forum C Programming
    Replies: 18
    Last Post: 05-29-2008, 05:59 AM
  2. function pointers
    By benhaldor in forum C Programming
    Replies: 4
    Last Post: 08-19-2007, 10:56 AM
  3. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM
  4. Staticly Bound Member Function Pointers
    By Polymorphic OOP in forum C++ Programming
    Replies: 29
    Last Post: 11-28-2002, 01:18 PM