File tree Expand file tree Collapse file tree 1 file changed +12
-2
lines changed
Expand file tree Collapse file tree 1 file changed +12
-2
lines changed Original file line number Diff line number Diff line change @@ -13,6 +13,7 @@ void push(float element);
1313
1414int main (int argc , char * argv []) {
1515 char Error = 0 ;
16+ int op_count = 0 ;
1617
1718 // Using int instead of size_t for loop variable to match signed argc
1819 // This prevents sign comparison warnings
@@ -29,19 +30,23 @@ int main(int argc, char *argv[]) {
2930 char op = * argv [i ];
3031 switch (op ) {
3132 case '+' :
33+ op_count ++ ;
3234 push (number1 + number2 );
3335 break ;
3436
3537 case '-' :
38+ op_count ++ ;
3639 push (number1 - number2 );
3740 break ;
3841
3942 case '*' : // This char might require to be escaped when passed
4043 // as an argument.
44+ op_count ++ ;
4145 push (number1 * number2 );
4246 break ;
4347
4448 case '/' :
49+ op_count ++ ;
4550 if (number2 == 0 ) {
4651 Error = 4 ;
4752 } else {
@@ -87,8 +92,13 @@ int main(int argc, char *argv[]) {
8792
8893 return EXIT_FAILURE ;
8994 }
90-
91- printf ("result: %.3f" , pop ());
95+
96+ if (op_count == 0 && argc > 2 ) {
97+ printf ("Error: Operator is missing!" );
98+ return EXIT_FAILURE ;
99+ } else {
100+ printf ("result: %.3f" , pop ());
101+ }
92102
93103 return EXIT_SUCCESS ;
94104}
You can’t perform that action at this time.
0 commit comments