I am trying to implement this stackTop function into my program, but I am having a hard time trying to understand why it does not display the member information. The function works but I don't understand why no member information is displayed.
struct stackNode{
char vehicleType;
string license;
int vehicleCapacity;
stackNode *next;
};
struct stackMeta{
int count;
stackNode *head;
};
bool StackTop(stackMeta *stackHead)
{
//local variables
bool success;
//stackNode *head;
char vehicleT;
string vehicleLicense;
int vehicleCapacity;
// dataTop = new stackNode;
if(!IsEmptyStack(stackHead))
{
success = false;
}
else
{
vehicleT = stackHead->head->vehicleType;
vehicleLicense = stackHead->head->license;
vehicleCapacity = stackHead->head->vehicleCapacity;
success = true;
}
//This is a test cout. It displays the address of the top
//node but it does not display the data in the members.
cout << "Yes " << stackHead->head << vehicleT << endl;
return success;
}
guesses:
- It works perfectly, but because you didn't put an space between the outputs you are confusing `vehicleT' with part of the address.
- `vehicleT' does not contain a printable character
- The stack is not empty so the condition in line 24 is true, `vehicleT' is uninitialized.
Thank you so much. I needed an extra set of eyes. I've been staring at this code for a long time. The funny thing is that I had the same problem with a different function. I changed the if test and forgot to remove the !.