gpt4 book ai didi

C while循环条件

转载 作者:太空狗 更新时间:2023-10-29 16:10:16 24 4
gpt4 key购买 nike

我正在为我的 CS 课阅读计算机系统,我遇到了一个令我困惑的 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++;
}

while (*buf && (*buf == ’ ’)) /* Ignore spaces */ 

while 循环有两个逻辑操作数 && 但我不明白第一个操作数 (*buf) 的目的是什么>。第二个操作数正在检查是否有空格,但我认为第二个操作数本身就足以满足此循环的目的。

最佳答案

是的,*buf && 是多余的。


*buf'\0' 为假,对其他一切为真。

*buf == ' '' ' 为真,对其他一切都为假,包括 '\0'.

关于C while循环条件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49225467/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com