找不出哪里有问题,在pta里运行错误但是在编译器里按要求输入结果感觉没啥问题,求解

img

img

img


找不出哪里有问题,在pta里运行错误但是在编译器里按要求输入结果感觉没啥问题,求解

printf函数中,你有个单词拼写错了,digit 你写成了 dight

img

如有帮助,望采纳,谢谢。

img

试下提示的要求,是否满足。

#include <stdio.h>
int main(void)
{
    char c;
    int i, letter = 0, blank = 0, digit = 0, other = 0;
    for (i = 0; i < 10; i++)
    {
        c = getchar();
        if (c >= '0' && c <= '9')
            digit++;
        else if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z'))
            letter++;
        else if (c == ' ')
            blank++;
        else if (c == '\n')
            blank++;
        else
            other++;
    }
    printf("letter = %d, blank = %d, digit = %d, other = %d", letter, blank, digit, other);
    return 0;
}

是不是blank与前面的逗号之间不需要空格啊。把每项前面的空格去掉看看

#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
int main()
{
int i, d = 0, l = 0, b = 0, o = 0;
char ch;
for (i = 1; i <= 10; i++)
{
ch = getchar();
if (ch <= '9' && ch >= '0')
d++;
else if ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z'))
l++;
else if (ch == '\n' || ch == ' ')
b++;
else
o++;
}
printf("letter = %d, blank = %d, dight = %d, other = %d", l, b, d, o);
}

您好,我是有问必答小助手,您的问题已经有小伙伴帮您解答,感谢您对有问必答的支持与关注!
PS:问答VIP年卡 【限时加赠:IT技术图书免费领】,了解详情>>> https://vip.csdn.net/askvip?utm_source=1146287632

代码没什么问题:

#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
int main()
{
    int i, d = 0, l = 0, b = 0, o = 0;
    char ch;
    for (i = 0; i < 10; i++)  //for (i = 1; i <= 10; i++)
    {
        ch = getchar();
        if (ch <= '9' && ch >= '0')
            d++;
        else if ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z'))
            l++;
        else if (ch == '\n' || ch == ' ')
            b++;
        else
            o++;
    }
    printf("letter = %d, blank = %d, dight = %d, other = %d", l, b, d, o);
    return 0; //修改 
}