Hello all, I'm a beginner in C.
I want to implement a stack data structure.
typedef struct stackNode
{
int value;
struct stackNode *next;
} stackElement;
typedef stackElement *stackPtr;
stackPtr newElement(void)
{
stackPtr element;
element = (stackPtr)malloc(sizeof(stackElement));
element->next = NULL;
return(element);
}
in main function I declare it...
int main(void)
{
stackPtr tmp;
stackPtr stack = NULL;
....
tmp = newElement();
return 0;
}
why every time i try to use newElement()
it gives a runtime error (Segmentation fault,
core dumped)?
And what does the error mean?
Thanks for the help,
Ronald