Обновить cv3/program.c

This commit is contained in:
Yevhen Kozirovskyi 2024-10-17 16:54:08 +00:00
parent 8c3c003af9
commit f71ad133b9

View File

@ -1,3 +1,4 @@
#include <ctype.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
@ -46,13 +47,14 @@ int main() {
while (fgets(bufer, sizeof(bufer), stdin) != NULL) { while (fgets(bufer, sizeof(bufer), stdin) != NULL) {
char* konec; char* konec;
double chislo = strtod(bufer, &konec); double chislo = strtod(bufer, &konec);
if (chislo == 0 && strcmp(bufer, "0\n") != 0) {
printf("bad input\n");
exit(1);
}
if (*konec == '\n' && *bufer != '\n' && *bufer != ' ') { if (*konec == '\n' && *bufer != '\n' && *bufer != ' ') {
if (konec - bufer == 1) {
printf("bad input\n");
exit(1);
}
push(&stek, chislo); push(&stek, chislo);
} else if (strcmp(konec, "+\n") == 0) { } else if (strcmp(konec, "+\n") == 0) {
if (isEmpty(&stek)) { if (isEmpty(&stek)) {
printf("no input\n"); printf("no input\n");
exit(1); exit(1);
@ -106,6 +108,9 @@ int main() {
exit(1); exit(1);
} }
push(&stek, a / b); push(&stek, a / b);
} else if (isalpha(konec[-1])) {
printf("bad input\n");
exit(1);
} else { } else {
printf("bad input\n"); printf("bad input\n");
exit(1); exit(1);