I am writing a series of stack manipulation functions in C, and I am having an issue with pop. The tester file requires a return of ItemT where ItemT is just the define for char *.
ItemT popStack(StackP stackPtr) {
if (isEmptyStack(stackPtr)) {
fprintf(stderr, "\nERROR: Empty stack...\n");
return NOTHING;
}
else {
ItemT item = *((stackPtr->items));
(stackPtr->top)--;
(stackPtr->count)--;
--(stackPtr->items);
return item;
}
}
items of (stackPtr->items) is a ItemT *, or a char **
in the line ItemT item = *((stackPtr->items)); I am trying to get the char * that stackPtr->items is pointing to and set it to the variable item and then return item.
My bug is the return, when the tester program calls pop and tries to display the value returned by popStack() what is displayed is this:

The stack is full of char * and peek works just fine. It is just pop here and seems to not work.
I just assume that that is bad data or random values stored in empty memory addresses. Thus, I have no idea what I am doing wrong. Any way someone can explain to me what is wrong here? and is there an issue with my method of decrementing the items in the struct?
EDIT 1:
the call to popStack() looks something like:
printf("%s\n", popStack(stackP)); where stackP is the pointer to the struct that contains all the info. You can ignore top and count because they work effectively. The --(stackPtr->items) I have just learned is absolutely ineffective.
*((stackPtr->items))it's not very easy to follow, instead juststackPtr->items[0].topis for, so shouldn't it beitem = stackPtr->items[stackPtr->top];and don't alter the pointer, or else how are you going to free it?toporcountand it would work the same as long as i use the logic correctly.