Hi, Im getting this error message :
error C2129: static function 'int emptyStack(STACK *)' declared but not defined
What im I doing wrong , here im clueless.
Code:
#include "header.h"
#define EOF (-1)
int main(void)
{
/*Local delcarations*/
int returned = 1;
STACK *stack;
void *ptr;
void *number;
/*Statements*/
stack = createStack();
printf("Enter a number");
scanf("%d",&number);
/*Fill stack*/
while((number != -1) && (returned != 0)){
returned = pushStack(stack,number);
printf("Enter next number:<EOF> to stop");
scanf("%d",&number);
}
/*Now print numbers in reverse*/
while (!emptyStack(stack)){
ptr = popStack(stack);
printf("%d",ptr);
}
stack = destroyStack(stack);
}
Code:
/*header.h*/
#include <stdlib.h>
#include <stdio.h>
typedef struct node
{
void *dataPtr;
struct node *link;
}STACK_NODE;
typedef struct
{
int count;
STACK_NODE *top;
}STACK;
STACK *createStack(void);
int pushStack(STACK *stack,void *dataInPtr);
void *popStack(STACK *stack);
int emptyStack(STACK *stack);
STACK *destroyStack(STACK *stack);
Code:
*createStack*/
/*This algorithm creates an empty stack.
Pre nothing
Post returns pointer to a null stack.
-or- NULL if overflow.
*/
#include "header.h"
STACK *createStack(void)
{
/* local declarations*/
STACK *stack;
/*statements*/
stack = (STACK *) malloc(sizeof (STACK));
if (stack)
{
stack->top = NULL;
stack->count = 0;
}/*if*/
return stack;
}/*createStack*/
Code:
#include "header.h"
/*====pushStack====*/
/*This function pushes an item onto the stack.
Pre stack is a pointer to the stack
dataPtr is a pointer to the data to be inserted
Post returns 1 if success; 0 if heap overflow.
*/
int pushStack(STACK *stack,void *dataInPtr)
{
/*local declarations*/
STACK_NODE *newPtr;
/*statements*/
newPtr = (STACK_NODE *) malloc(sizeof(STACK_NODE));
if(!newPtr)
return 0;
newPtr->dataPtr = dataInPtr;
newPtr->link = stack->top;
stack->top = newPtr;
(stack->count)++;
return 1;
}/*pushStack*/
Code:
#include "header.h"
/*=====popStack=====*/
/*This function pops the item on the top of the stack.
Pre stack is a pointer to the stack.
Post returns pointer to user data if successfull
NULL if underflow
*/
void *popStack(STACK *stack)
{
/*local declarations*/
void *dataOutPtr;
STACK_NODE *temp;
/*statements*/
if (stack->count == 0)
dataOutPtr = NULL;
else
{
temp = stack->top;
dataOutPtr = stack->top->dataPtr;
stack->top = stack->top->link;
free(temp);
(stack->count)--;
}/*else*/
return dataOutPtr;
}/*popStack*/
Code:
#include "header.h"
/*===emptyStack====*/
/*This function determines if a stack is empty
Pre stack is a pointer to the stack
Post returns 1 if empty; 0 if data are in the stack
*/
int emptyStack(STACK *stack)
{
/*statements*/
return (stack->count == 0);
}/*emptyStack*/
Code:
#include "header.h"
/*====destroyStack====*/
/*This function releases all nodes to the heap
Pre A stack
Post returns null pointer
*/
STACK *destroyStack(STACK *stack)
{
/*local declarations*/
STACK_NODE *temp;
/*statements*/
if (stack)
{
/*Delete all nodes in stack*/
while (stack->top != NULL)
{
/*Delete data entry*/
free (stack->top->dataPtr);
temp = stack->top;
stack->top = stack->top->link;
free(temp);
}/*while*/
/*stack now empty.Destroy stack head node.*/
free(stack);
}/*if stack */
return NULL;
}/*destroyStack*/
Im studying at home , correspondence, so I can't ask anyone else really.
Thanks.