c - Getting request for member not a structure or union error -


i trying implement stack. have following stack struct:

struct stacknode  {   char data;   struct stacknode *nextptr; };  typedef struct stacknode stacknode;  typedef stacknode *stacknodeptr; 

when try use pop method, number of error messages. pop method is:

char pop(stacknodeptr *topptr ) {          if (isempty(topptr))    {     printf("can't pop element stack: stack empty.\n");     return 'n'; // arbitrary char end if, adjust later.   }   char c = topptr->data; //save data returned    // temporary structnodeptr save data   stacknodeptr temp; // temporary stacknodeptr   temp = malloc(sizeof(stacknodeptr));   temp->data = topptr->data;    //line 52, first error   temp->nextptr = topptr->nextptr;    //replace values in topptr, section have yet debug, faulty.   topptr->data = temp->nextptr->data;   //line 56, third error   topptr->nextptr = temp->nextptr;     free(temp);         return (c); } 

i following error messages:

52:22: error: request member ‘data’ in not structure or union 53:25: error: request member ‘nextptr’ in not structure or union 56:10: error: request member ‘data’ in not structure or union 57:10: error: request member ‘nextptr’ in not structure or union 

if make temp stacknode (and adjust -> . accordingly), error "request member ‘nextptr’ or ’data’ in not structure or union". in question given me, topptr must me stacknodeptr.

can me trouble shoot this?

your topptr pointer pointer struct (stacknodeptr *topptr = struct stacknode **topptr). should write (*topptr) -> data instead of topptr -> data.

in fact, line char c = topptr->data; should cause error.


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -