Undefined reference to All Functions as "push , pop ,createstack, etc.." I included all the header files correctly , but when I run it I get the error: undefined reference to '(function name)'. I get this error for all my functions. Below you can find the source code of all my three files.
Test.c
#include <stdio.h>
#include "Stack.h"
void printMessage() {
printf("\n(a) Read an element then Push it.\n");
printf("(b) Pop an element then display it.\n");
printf("(c) Returns a copy of the top-element of the stack without deleting it\n");
printf("(d) Exit.\n");
}
void userStackTop(Stack *ps, StackEntry *pe) {
pop(ps, pe);
push(ps, *pe);
}
Stack S;
StackEntry E;
int Size;
char Choice;
int main() {
setvbuf(stdout, NULL, _IONBF, 0); //Eclipse Bug for scanf and printf
createStack(&S);
printf("Welcome: ");
printMessage();
while (scanf("\n%c", &Choice)) {
if (Choice == 'a' || Choice == 'A') {
printf("Enter Your Element: ");
scanf("\n%c", &E);
if (!stackFull(&S)) {
push(&S, E);
printf("Element (%c) is pushed into stack.\n\n",E);
}
else
printf("\n\nSorry , The Stack is Full!\n\n");
} else if (Choice == 'b' || Choice == 'B') {
if (!stackEmpty(&S)) {
pop(&S, &E);
printf("\n\nThe Element (%c) is popped.\n\n", E);
} else
printf("\n\nSorry , The Stack is Empty!\n\n");
} else if (Choice == 'c' || Choice == 'C') {
if (!stackEmpty(&S)) {
//stackTop(&S, &E);
userStackTop(&S, &E);
printf("Last Element Pushed in the stack is (%c).\n",E);
} else
printf("\n\nSorry , The Stack is Empty!\n\n");
} else if (Choice == 'd' || Choice == 'D')
return 0;
printMessage();
}
return 0;
}
Stack.c
#include "Stack.h"
void createStack(Stack *ps) {
ps->top = 0;
}
void push(Stack *ps, StackEntry e) {
ps->Data[ps->top++] = e;
}
void pop(Stack *ps, StackEntry *pe) {
*pe = ps->Data[ps->top - 1];
ps->top--;
}
int stackEmpty(Stack *ps) {
if (ps->top <= 0)
return 1;
else
return 0;
}
int stackFull(Stack *ps) {
if (ps->top == MAXSTACK - 1)
return 1;
else
return 0;
}
int stackSize(Stack *ps) {
return ps->top + 1;
}
void stackTop(Stack *ps, StackEntry *pe) {
*pe = ps->Data[ps->top-1];
}
Stack.h
#ifndef STACK_H_
#define STACK_H_
typedef char StackEntry;
#define MAXSTACK 10
typedef struct stack {
int top;
StackEntry Data[MAXSTACK];
} Stack;
void createStack(Stack *ps);
void push(Stack *ps, StackEntry e);
void pop(Stack *ps, StackEntry *pe);
int stackEmpty(Stack *ps);
int stackFull(Stack *ps);
int stackSize(Stack *ps);
void stackTop(Stack *ps, StackEntry *pe);
#endif /* STACK_H_ */
Stack.C. How do you build your program? Do you use an IDE (which one?), or do you use GNU Make (if so add your Makefile to the question), or CMake (if so add your CMakeLists.txt) to the question.