printf函数中,你有个单词拼写错了,digit 你写成了 dight
如有帮助,望采纳,谢谢。
试下提示的要求,是否满足。
#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);
}
代码没什么问题:
#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; //修改
}