Add division by zero habdling, fixes #4
This commit is contained in:
parent
eca8a60141
commit
dc6a3a0804
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue