struct Stack {
char top;
unsigned capacity;
char* array;
};
char*pop(struct Stack* stack)
{
if (isEmpty(stack)){
printf("Stack underflow\n");
}
return stack->array[stack->top--];
}
char* peek(struct Stack* stack)
{
if (isEmpty(stack)){
printf("Stack underflow\n");
}else{
return stack->array[stack->top];
}}
***main.c:56:29: warning: return makes pointer from integer without a cast [-Wint-conversion]
main.c:67:24: warning: return makes pointer from integer without a cast [-Wint-conversion]
I have these two warnings and I can't deal with them, I need help, please
the warnings are in these two lines :
return stack->array[stack->top--]......
return stack->array[stack->top]
Change both the function return types to char
instead of char*
since stack->array[stack->top]
is going to return a character and not a char*
Also, on a side note, your peek()
doesn't return anything from the if
branch. Change that to return something ( a dummy character as per your program logic) or just make it a standalone if
statement like the one in pop()
.