- 论坛徽章:
- 0
|
#include <ctype.h>
int getch(void);
void ungetch(int);
/* getop:取下一个运算符或数值运算分量*/
int getop(char s[ ] )
{
int i, c;
while ( (s[0] = c = getch() ) == ' ' || c == '\t' )
;
s[1] = '\0';
if ( !isdigit( c ) && c != '.' )
return c; /* 不是数*/
i = 0;
if ( isdigit( c ) ) /* 收集整数部分*/
while ( isdigit(s[++i] = c = getch( ) ) )
;
if (c == '.' ) /* 收集小数部分*/
while ( isdigit(s[++i] = c = getch( ) ) )
s = '\0';
if (c != EOF )
ungetch( c );
return NUMBER;
}
其中:if ( isdigit( c ) ) /* 收集整数部分*/
while ( isdigit(s[++i] = c = getch( ) ) )
;
if (c == '.' ) /* 收集小数部分*/
while ( isdigit(s[++i] = c = getch( ) ) )
s = '\0';
这两个语句为什么不用一个if语句,而要分开,请高手指点一下!最要帮我分析一下!谢谢! |
|