I am getting a segmentation fault 11 where my if and if-else statements begin in the EVALUATE function here. I've only included the MAIN and the EVALUATE functions, as my other areas of the program I believe it be working properly. I am a novice to C and could use some help. Can anyone identify where I'm going wrong here?
Code:
// Evaluate
void evaluate(char expression[]) {
int counter = 0;
while (expression[counter]) {
char temp = expression[counter];
if(expression[counter]=='+') add(); // if "+" then call addition. isn't advancing past this point.....
else if(expression[counter]=='-') sub(); // if "-" then call subtraction.
else if(expression[counter]=='*') mult(); // if "*" then call multiplication.
else if(expression[counter]=='/') divide(); // if "/" then call division.
else push(temp - '0'); // otherwise, assume it is number. push to stack.
counter++;
}
}
// Main
int main() {
printf("Enter the expression to be evaluated: ");
char string[100];
scanf("%s", string);
evaluate(string);
printFinal();
}