我正在上计算机科学课程,遇到了一个让我困惑的while循环条件,以下是代码:
int parseline(char *buf, char **argv)
{
char *delim; /* Points to first space delimiter */
int argc; /* Number of args */
int bg; /* Background job? */
buf[strlen(buf)-1] = ’ ’; /* Replace trailing ’\n’ with space */
while (*buf && (*buf == ’ ’)) /* Ignore leading spaces */
buf++;
/* Build the argv list */
argc = 0;
while ((delim = strchr(buf, ’ ’))) {
argv[argc++] = buf;
*delim = ’\0’;
buf = delim + 1;
while (*buf && (*buf == ’ ’)) /* Ignore spaces */
buf++;
}
In
while (*buf && (*buf == ’ ’)) /* Ignore spaces */
while
循环有两个操作数用于逻辑运算符&&
,但我不理解第一个操作数(*buf)
的目的。第二个操作数检查空格,但我认为第二个操作数本身足以满足此循环的目的。
buf
cannot beNULL
after this:buf = delim + 1;
- Jean-François Fabre