Home > Back-end >  C programming language (second edition) reverse polish calculator segmentation to compile errors aft
C programming language (second edition) reverse polish calculator segmentation to compile errors aft

Time:10-02

K& R "C programming language", to reverse polish calculator program 4.3 chapter and put in a file, 4.5 chapters, divided into several source files, a program but error (when put in a file is not wrong), split into multiple source files after the main function is as follows:
The main ()
{
The int type.
Double op2;
Char s [MAXOP];

While ((type=getop (s)). EOF)={
The switch (type) {
The case NUMBER:
Push (atof (s));
break;
Case: '+'
Push (pop () + pop ());
break;
Case: '*'
Push (pop () * pop ());
break;
In case the '-' :
Op2=pop ();
Push (pop () - op2);
break;
Case '/' :
Op2=pop ();
If (op2!=0.0)
Push (pop ()/op2);
The else
Printf (" error: zero divisor \ n ");
break;
Case '\ n' :
Printf (" \ n \ t %. 8 g ", pop ());
break;
Default:
Printf (" error: unknown command % s \ n ", s);
break;
}
}
return 0;
}
Prompt is switch statement of the first case "case NUMBER:" there are two mistakes
The error C2143: syntax errors: lack of ":" (the ";" In front of)
Error C2143: syntax errors: lack of ";" (in front of the ":"),
But why there are no errors when put in a file?

CodePudding user response:

Include the header file? Or when moving the character or what wrong...
  • Related