|
50鱼币
本帖最后由 wow7jiao 于 2019-3-31 20:46 编辑
改写第4章中的后缀计算器程序,用scanf函数和(或)sscanf函数实现输入及数的转换.
#include <stdio.h>
#include <stype.h>
#define NUMBER '8'
int getop(char s[])
{
int c, i, rc;
static char lastc[] = " ";---------------------> 这个字符串里面就一个空格
sscanf(lastc, "%c", &c);--------------------->sscanf读一个空字符,c里面应该没有东西啊
lastc[0] = ' ';----------------------------------->这里有lastc[0] = 空格,这三条语句无意义啊
while ((s[0] = c) == ' ' || c == '\t' )
if (scanf("%c", &c) == EOF)
c = EOF;
s[1] = '\0';
if (!isdigit(c) && c != '.')
return c;
i = 0;
if (isdigit(c))
do {
rc = scanf("%x", &c);
if (!isdigit(s[i++] = c))
break;
} while (rc != EOF);
if (c == '.')
do {
rc = scanf("%c", &c);
if (!isdigit(s[++i] c))
break;
} while (rc != EOF);
s[i] = '\0';
if (rc != EOF)
lastc[0] = c;
return NUMBER;
}
|
|