小编fio*_*za2的帖子

'if'语句没有'else'就没有预期的表现

只是一个简单的问题; 我一直在通过K&R和数字/空白/其他计数器的代码工作正常.然而,虽然我试图了解我的功能,但else我遇到了一些不能按预期工作的东西.

书中的代码如下:

#include <stdio.h>

/* count digits, white space, others */
main()
{
    int c, i, nwhite, nother;
    int ndigit[10];

    nwhite = nother = 0;
    for (i = 0; i < 10; ++i)
        ndigit[i] = 0;

    while ((c = getchar()) != EOF)
        if (c >= '0' && c <= '9')
            ++ndigit[c-'0'];
        else if (c == ' ' || c == '\n' || c == '\t')
            ++nwhite;
        else
            ++nother;

     printf("digits =");
    for (i = 0; i < 10; …
Run Code Online (Sandbox Code Playgroud)

c if-statement

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

标签 统计

c ×1

if-statement ×1