[英]Confusion about calculator program
int getop(char s[])
{
int i = 0, c, next;
/* Skip whitespace */
while((s[0] = c = getch()) == ' ' || c == '\t')
;
s[1] = '\0';
/* Not a number but may contain a unary minus. */
if(!isdigit(c) && enter code herec != '.' && c != '-')
return c;
if(c == '-')
{
next = getch();
if(!isdigit(next) && next != '.')
return c;
c = next;
}
else
c = getch();
while(isdigit(s[++i] = c)) //HERE
c = getch();
if(c == '.') /* Collect fraction part. */
while(isdigit(s[++i] = c = getch()))
;
s[i] = '\0';
if(c != EOF)
ungetch(c);
return NUMBER;
};
如果没有空格或制表符,那么s [0]将初始化什么值呢?.......&s [1] ='\\ 0'的用途是什么
while((s[0] = c = getch()) == ' ' || c == '\t')
读取字符,直到没有制表符或空格为止。
s[1] = '\0';
将char数组s转换为C格式的适当字符串(c中的所有字符串都必须以空字节结尾,该空字节由'\\ 0'表示)。
如果没有空格或制表符,那么您将陷入无限循环。
s [1] ='\\ 0'是标记结束的一种方式,因此strlen()之类的函数知道何时停止读取c字符串。 它称为“ Null-Terminated”字符串: http : //chortle.ccsu.edu/assemblytutorial/Chapter-20/ass20_2.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.