I am programming in C.
Considering the following Code.
My structure is defined as:
// Define the stack
struct stackNode {
char data;
struct stackNode *nextPtr;
};
typedef struct stackNode StackNode;
typedef StackNode *StackNodePtr;
The following Variables are used:
StackNode topTracker; // The pointer of this stackNode will always point to the top of the stack
And I am trying to complete the following function.
char pop( StackNodePtr *topPtr ){
char returnable;
// store the Node.data from the top of the stack
returnable = *topPtr.data; //[1]
// Set the next Node to the top of the stack
topTracker.nextPtr = *topPtr.nextPtr; //[2]
// return the Node data.
return returnable;
The problem is I get the following error: at Point [1] & [2] respectively
“request for member data' in something not a structure or union"nextPtr’ in something not a structure or union”
"request for member
How do I get around this error and actually access the data and nextPtr of the pointer *topPtr? Given that *topPtr will be a pointer to an actual StackNode at runtime.
topPtris of typeStackNodePtr*which is an alias forStackNode**. This means that*topPtris of typeStackNode*which is a pointer type and you must access the members using->.Also beware that the operators
.and->bind stronger than unary*. You therefore have to use parenthesis to manipulate the evaluation order:or