Home > Back-end >  The switch for help
The switch for help

Time:04-14

#include
#include
#include
# include "header. H"
Void main ()
{
SqStack OPTR OPND;
OperandType a, b, d, x, theta.
Char c; Deposit//keyboard input string
Char z [6].//store integer string
int i,j;
Int s=1;
The menu ();
InitStack (& amp; OPTR);//initialization operator stack
Push (& amp; OPTR, '=');//=expression is end
InitStack (& amp; OPND);//initialize the operand stack
Do {
The scanf (" % d ", & amp; J);
The switch (j) {
Case 1://1. The input expression
Printf (" input expression \ n ");
The scanf (" % s ", c);
break;
Case 2://2. The output expression
Printf (" % s ", c);
break;
Case 3://3. Judge whether the bracket of the expression matching and calculating the value of the expression
GetTop (& amp; OPTR, & amp; x);
While (c!='=' | | x!='=')
{
If (In (c))//is one of the seven kinds of operator
{
The switch (Precede (x, c))
{
Case '& lt; "://currently has pressure stack after an operator (x) than an operator (c) low, will press c stack
Push (& amp; OPTR, c);
c=getchar();
break;
Case: '='
Pop (& amp; OPTR, & amp; x);//to take off the brackets and receive the next character
c=getchar();
break;
Case '& gt; ':
Pop (& amp; OPTR, & amp; Theta);//return stack operation and the result was pressed into the OPND
Pop (& amp; OPND, & amp; B);
Pop (& amp; OPND, & amp; A);
Push (& amp; OPND to Operate (a, theta, b));
break;
}
}
Else if (c & gt;='0' & amp; & C & lt;='9')//c is the operand
{
I=0;
Do
{
Z [I]=c;
I + +;
c=getchar();
} while (c & gt;='0' & amp; & C & lt;='9');
[I] z=0;
D=atoi (z);//a character array to integer in d
Push (& amp; OPND, d);
}
Else for illegal characters//c
{
Printf (" ERROR3 \ n ");
exit(1);
}
GetTop (& amp; OPTR, & amp; x);
}
GetTop (& amp; OPND, & amp; x);
StackDestroy (& amp; OPTR);
StackDestroy (& amp; OPND);
Printf (" % d \ n ", x);
break;
Case 4://4. Out
S=0;
break;
}
}
While (s==1);
Printf (" have withdrawn from the \ n ");
}


After entering the switch, the input 1, cannot enter 2, could you tell me how to change to? I'm too food

CodePudding user response:

Code is not complete, help arrange, 2 places have change, for reference:
 # include 
#include
#include
//# include "header. H"
Void main ()
{
SqStack OPTR OPND;
OperandType a, b, d, x, theta.
Char c; Deposit//keyboard input string????
Char z [6].//store integer string
int i,j;
Int s=1;
The menu ();
InitStack (& amp; OPTR);//initialization operator stack
Push (& amp; OPTR, '=');//=expression is end
InitStack (& amp; OPND);//initialize the operand stack
Do {
The scanf (" % d ", & amp; J);
The switch (j) {
Case 1://1. The input expression
Printf (" input expression \ n ");
The scanf (" % c ", & amp; c);//the scanf (" % s ", c); Where c is a single character, not string error 1
break;
Case 2://2. The output expression
Printf (" % c ", c);//printf (" % s ", c); Error 2
break;
Case 3://3. Judge whether the bracket of the expression matching and calculating the value of the expression
GetTop (& amp; OPTR, & amp; x);
While (c!='=' | | x!='=')
{
If (In (c))//is one of the seven kinds of operator
{
The switch (Precede (x, c))
{
Case '& lt; "://currently has pressure stack after an operator (x) than an operator (c) low, will press c stack
Push (& amp; OPTR, c);
c=getchar();
break;
Case: '='
Pop (& amp; OPTR, & amp; x);//to take off the brackets and receive the next character
c=getchar();
break;
Case '& gt; ':
Pop (& amp; OPTR, & amp; Theta);//return stack operation and the result was pressed into the OPND
Pop (& amp; OPND, & amp; B);
Pop (& amp; OPND, & amp; A);
Push (& amp; OPND to Operate (a, theta, b));
break;
}
}
Else if (c & gt;='0' & amp; & C & lt;='9')//c is the operand
{
I=0;
Do {
Z [I]=c;
I + +;
c=getchar();
} while (c & gt;='0' & amp; & C & lt;='9');
[I] z=0;
D=atoi (z);//a character array to integer in d
Push (& amp; OPND, d);
}
Else for illegal characters//c
{
Printf (" ERROR3 \ n ");
exit(1);
}
GetTop (& amp; OPTR, & amp; x);
}
GetTop (& amp; OPND, & amp; x);
StackDestroy (& amp; OPTR);
StackDestroy (& amp; OPND);
Printf (" % d \ n ", x);
break;
Case 4://4. Out
S=0;
break;
}
} while (s==1);
Printf (" have withdrawn from the \ n ");
}
  • Related