I’m trying to write a simple stack code and I get this code from a data structure book but it fails when i try to compile.
bool pushStack (STACK* stack, void* dataInPtr)
{
STACK_NODE* newPtr;
newPtr = (STACK_NODE*) malloc(sizeof(STACK_NODE));
if(!newPtr)
return FALSE;
newPtr->dataPtr = dataInPtr;
newPtr->link = stack->top;
stack->top = newPtr;
(stack->count)++;
return TRUE;
}
For example for this code, compiler says
Error 1 error C2061: syntax error : identifier 'pushStack'
Error 2 error C2059: syntax error : ';'
Error 3 error C2059: syntax error : 'type'
How can we resolve this? I tried to change TRUE to true, but it’s not worked.
C doesn’t have a
booldata type (C++ does, though). Have the function return anint, and return1forTRUEand0forFALSE. Alternatively,#DEFINE TRUE 1and#DEFINE FALSE 0.