I have four .c files and 1 .h file. Please bear with me, the problem is only on one line. First a bit of context:
main.c
Code:
#include <stdlib.h>#include <stdio.h>
#include "headerfile.h"
int main(){
char* postfix;
char* infixedUserInput = getKeyboardInput();
postfix = convertToPostfix(infixedUserInput);
return 0;
}
stackUtilities.c
Code:
#include <stdio.h>#include <stdlib.h>
#define MAX_STACK_SIZE 100
#define OPENING_PARENTHESIS (
struct NumStack operandStack = {.stackPointer = 0);
struct CharStack operatorStack = {.stackPointer = 0};
void pushNum(struct NumStack *stack, double pushedValue){
if (stack -> stackPointer < MAX_STACK_SIZE) {
stack -> stackValue[stack -> stackPointer++] = pushedValue;
}
else {
fprintf(stderr, "Number Stack full, can't push %g\n", pushedValue);
exit(-1);
}
}
double popNum(struct NumStack stack){
if (stack.stackPointer > 0){
return stack.stackValue[--stack.stackPointer];
}
else {
fprintf(stderr, "Number Stack empty\n");
exit(-1);
}
}
void pushChar(struct CharStack *stack, char pushedValue){
if (stack -> stackPointer < MAX_STACK_SIZE) {
stack -> stackValue[stack -> stackPointer++] = pushedValue;
}
else {
fprintf(stderr, "Character Stack full, can't push %g\n", pushedValue);
exit(-1);
}
}
char popChar(struct CharStack stack){
if (stack.stackPointer > 0){
return stack.stackValue[--stack.stackPointer];
}
else {
fprintf(stderr, "Character Stack empty\n");
exit(-1);
}
}
void updateStacks(struct NumStack *operandStack, struct CharStack *operatorStack){
double answer;
char operation;
char operatorStackPointer = operatorStack -> stackPointer;
if (operatorStackPointer > 0){
while((operation = popChar(*operatorStack)) != 'OPENING_PARENTHESIS'){
double secondOperand = popNum(*operandStack);
double firstOperand = popNum(*operandStack);
switch(operation){
case '+':
answer = add(firstOperand, secondOperand);
break;
case '-':
answer = subtract(firstOperand, secondOperand);
break;
case '*':
answer = multiply(firstOperand, secondOperand);
break;
case '/':
answer = divide(firstOperand, secondOperand);
break;
}
pushNum(*operandStack, answer);
}
}
}
solveArithmeticEquation.c
Code:
#include <stdlib.h>#include "headerfile.h"
#define CLOSING_PARENTHESIS )
void convertToPostfix(char *infix){
char token;
while(token = getToken(*infix) != '\0'){
if(token == isdigit(token)){
pushNum(&operandStack, atoi(token));
}
else if(token != isdigit(token)){
pushChar(operatorStack, token);
}
else if(token == 'CLOSING_PARENTHESIS'){
updateStacks(&operandStack, &operatorStack);
}
}
}
mathUtilities.c
Code:
double add(double firstOperand, double secondOperand){ return firstOperand + secondOperand;
}
double subtract(double firstOperand, double secondOperand){
return firstOperand - secondOperand;
}
double multiply(double firstOperand, double secondOperand){
return firstOperand * secondOperand;
}
double divide(double firstOperand, double secondOperand){
return firstOperand / secondOperand;
}
headerFile.h
Code:
#define MAX_STACK_SIZE 100
void printCharacterArray(char*);
char* getKeyboardInput(void);
char getToken(char **);
void pushNum(struct NumStack, double);
double popNum(struct NumStack);
void pushChar(struct CharStack , char);
char popChar(struct CharStack);
double add(double, double);
double subtract(double, double);
double multiply(double, double);
double divide(double, double);
void updateStacks(struct NumStack *, struct CharStack *);
struct NumStack{
double stackValue[MAX_STACK_SIZE];
int stackPointer;
};
struct CharStack{
char stackValue[MAX_STACK_SIZE];
int stackPointer;
};
extern struct NumStack operandStack;
extern struct CharStack operatorStack;
EDIT: Error is on line 9 in the solveArithmeticEquation.c
Compiler is complaining of "type of formal parameter 1 is incomplete"
What I did do to make it work is by putting this all in one file and then it seems fine. So what seems to be the problem? I have genuinely run out of solutions.