Add division by zero habdling, fixes #4

This commit is contained in:
Inex Code 2020-03-13 13:09:08 +03:00
parent eca8a60141
commit dc6a3a0804
1 changed files with 6 additions and 0 deletions

View File

@ -104,6 +104,9 @@ int parse(char *s, STACK* stack) {
add(stack);
return 0;
} else if (*s == '/') {
if ((stack -> st[(stack -> cnt)-1]) == 0) {
return -2;
}
divide(stack);
return 0;
} else if (*s == 'x') {
@ -130,6 +133,9 @@ int main(int argc, char **argv) {
if (error == -1) {
fprintf(stderr, "Error parsing operand.\n");
return(1);
} else if (error == -2) {
fprintf(stderr, "Division by zero!");
return(2);
}
}
int i;