Fatal Errors
I'm working on a dynamically allocated stack. I have just about all of it written, but when I pass in the stack from the main to a function, I get an error. When I pass to fnInitStack I get: fatal error LNK1284: metadata inconsistent with COFF symbol table followed by a bunch of stuff I don't understand, including the words "mapped to" in the middle of it all. If I take out fnInitStack,initialize the stack when I declare it instead, and then pass the stack and a value to fnPushStack, I get: fatal error LNK1235: corrupt or invalid COFF symbol table. Does anyone know what these messeges mean and how I might fix them? I've never seen anything like this before, and I'm at a loss for what to do or why they would occur.
Thanks for any help.
//filename: stack.cpp
#include <stdio.h>
#include <malloc.h>
#include "stack.h"
void fnInitStack( StackPtr* hStack )
{
*hStack = NULL;
}
int fnIsEmptyStack( StackPtr pStack )
{
if( NULL == pStack )
return 1;
else
return 0;
}
DataType fnPopStack( StackPtr *hStack )
{
//don't forget to have scenarios for 0 and multiple elements of the stack
DataType data = 0;
StackPtr ptemp;
ptemp = *hStack;
*hStack = ptemp->next;
ptemp->data;
free( ptemp );
return data;
}
void fnPushStack( StackPtr *hStack, DataType x )
{
StackPtr ptemp = (StackPtr) malloc( sizeof(Node) );
ptemp->data = x;
ptemp->next = NULL;
if( NULL == *hStack )
{
*hStack = ptemp;
}
else
{
ptemp->next = *hStack;
*hStack = ptemp;
}
}
---
//filename: stack.h
#ifndef STACK_H
#define STACK_H
#include <stdio.h>
typedef int DataType;
typedef struct Node *StackPtr;
typedef struct Node
{
DataType data;
StackPtr next;
} Node;
void fnInitStack( StackPtr * );
int fnIsEmptyStack( StackPtr );
DataType fnPopStack( StackPtr * );
void fnPushStack( StackPtr *, DataType );
#endif
---
//filename: main.cpp
#include <stdio.h>
#include "stack.h"
int main()
{
StackPtr *stack = NULL;
fnInitStack( stack );
fnPushStack( stack , 3 );
return 0;
}
Thanks for any help.
