小编S.S*_*Sot的帖子

在循环主体中使用逗号运算符

我试图用两种不同的方式编写一个while循环,并注意到在两次条件下使用','不能按我认为的方式工作。我只是对实际发生的事情感到好奇。这是代码:

#include <stdio.h>

int main()
{
    int i = 0, lim = 1000, c;
    char s[lim];
    while (i < lim - 1, (c = getchar()) != '\n')
    {
        if (c != EOF)
        {
            s[i] = c;
        }
        else
        {   
            break;
        }
        ++i;
    }
    printf("%s\n", s);
    return 0;
}
Run Code Online (Sandbox Code Playgroud)
#include <stdio.h>

int main()
{
    int i = 0, lim = 1000, c;
    char s[lim];
    while (i < lim - 1, (c = getchar()) != '\n', c != EOF)
    {
        s[i] = …
Run Code Online (Sandbox Code Playgroud)

c loops while-loop

0
推荐指数
1
解决办法
46
查看次数

标签 统计

c ×1

loops ×1

while-loop ×1