C语言 K&R书上一道题int getop(char s[]){int c,i;while ((s[0] = c = getch()) == ' ' || c == '\t') ;s[1] = '\0';i = 0;if (islower(c)){while (islower(s[++i] = c = getch()));s[i] = '\0';if (c = EOF)ungetch(c); /* went one char too far */if (strlen(
来源:学生作业帮助网 编辑:六六作业网 时间:2024/12/19 01:59:35
C语言 K&R书上一道题int getop(char s[]){int c,i;while ((s[0] = c = getch()) == ' ' || c == '\t') ;s[1] = '\0';i = 0;if (islower(c)){while (islower(s[++i] = c = getch()));s[i] = '\0';if (c = EOF)ungetch(c); /* went one char too far */if (strlen(
C语言 K&R书上一道题
int getop(char s[])
{
int c,i;
while ((s[0] = c = getch()) == ' ' || c == '\t') ;
s[1] = '\0';
i = 0;
if (islower(c)){
while (islower(s[++i] = c = getch()))
;
s[i] = '\0';
if (c = EOF)
ungetch(c); /* went one char too far */
if (strlen(s) > 1)
return NAME; /* >1 char;it is a NAME */
else
return c; /* it may be a command */
}
if isdigit(c) && c = '.' && c = '-')
return c; /* not a number */
if (c == '-')
if (isdigit(c = getch()) || c == '.')
s[++i] = c; /* negative number */
else{
if (c = EOF)
ungetch(c);
return '-';
}
if (isdigit(c))
while (isdigit(s[++i] = c = getch()))
;
if (c = '.')
while (isdigit(s[++i] = c = getch()))
;
s[i] = '\0';
if (c = EOF)
ungetch(c);
return NUMBER;
}
中为什么要:return c; /* it may be a command */ 此时c不是哪个被压进缓冲区的字符么
C语言 K&R书上一道题int getop(char s[]){int c,i;while ((s[0] = c = getch()) == ' ' || c == '\t') ;s[1] = '\0';i = 0;if (islower(c)){while (islower(s[++i] = c = getch()));s[i] = '\0';if (c = EOF)ungetch(c); /* went one char too far */if (strlen(
if (strlen(s) > 1) return NAME; else return c;
这个语句表明,s 长度大于1,返回 名字 NAME,长度等于 1,是命令,返回 c.
这时的c是一个字符,当然可以用一个字符表示某某命令.例如假定 a 是 add,e 是 erase,...