Update cv3/program.c

This commit is contained in:
Yurii Yakovenko 2024-10-14 19:58:34 +00:00
parent 411e43d1be
commit 60e3495099

View File

@ -1,7 +1,7 @@
#include <stdio.h> #include <stdio.h>
#include <assert.h> #include <assert.h>
#include <stdlib.h> #include <stdlib.h>
////////@@@@@@@@@@@
#define STACK_SIZE 500 #define STACK_SIZE 500
struct Stack struct Stack
@ -48,7 +48,7 @@ int main()
struct Stack mystack; struct Stack mystack;
mystack.size=0; mystack.size=0;
//memset(&mystack,0,sizeof(struct Stack)); //memset(&mystack,0,sizeof(struct Stack));
int err=0;
char buf[505]; char buf[505];
@ -73,7 +73,15 @@ int main()
{ {
case '+': rez=op1+op2; break; case '+': rez=op1+op2; break;
case '-': rez=op1-op2; break; case '-': rez=op1-op2; break;
case '/': rez=op1/op2; break; case '/':
if(c=='/' && op2==0)
{
err=1;
printf("division_by_zero\n");
}
else
rez=op1/op2;
break;
case '*': rez=op1*op2; break; case '*': rez=op1*op2; break;
} //p } //p
} }
@ -81,15 +89,17 @@ int main()
{ {
rez=atof(buf); rez=atof(buf);
} }
push_stack(&mystack, rez);
//printf(" %.2f\n", rez); if(!err)
print_stack(&mystack); {
push_stack(&mystack, rez);
//printf(" %.2f\n", rez);
print_stack(&mystack);
}
} }
}while(1); }while(1);
if(!err)
printf("no input\n"); printf("no input\n");
return 0; return 0;
} }