Update 'cv3/program.c'

This commit is contained in:
Daniel Ryzhuk 2020-10-14 16:57:47 +00:00
parent 0ac9d77192
commit 2f3fc5ad8a

View File

@ -24,10 +24,13 @@ int main(void) {
str[strlen(str) - 1] = 0; str[strlen(str) - 1] = 0;
// if number // if number
if(strlen(str) > 1 || (str[0] >= '0' && str[0] <= '9')) { if(strlen(str) > 1 || (str[0] >= '0' && str[0] <= '9')) {
char *p; my_exit(str[0] == '.', "bad input");
errno = 0; float res = 0.f;
float res = strtod(str,&p); int dots = 0;
my_exit(str[0] == '.' || errno || (*p) != 0, "bad input"); for(int i = 0; i < strlen(str); i++)
if(str[i]=='.') dots++;
else my_exit(str[i] < '0' || str[i] > '9', "bad input");
res = atof(str);
stack_push(p_stack, res); stack_push(p_stack, res);
} }
else { else {