解题思路:
其实不需要开数组,一个一个字符读入并判断就好了
注意事项:
结束不是'\0',也不是'\n',而是'EOF',即文件结束
参考代码:
#include <stdio.h> int main() { int word = 0, number = 0, space = 0, others = 0; int ch; while ((ch = getchar()) != EOF) { if ('a' <= ch && ch <= 'z' || 'A' <= ch && ch <= 'Z') { word++; } else if ('0' <= ch && ch <= '9') { number++; } else if (ch == ' ') { space++; } else { others++; } } printf("%d %d %d %d", word, number, space, others); return 0; }
0.0分
3 人评分
数组输出 (C语言代码)错误???浏览:558 |
C语言程序设计教程(第三版)课后习题5.7 (C语言代码)浏览:574 |
C语言程序设计教程(第三版)课后习题1.5 (C语言代码)浏览:526 |
图形输出 (C语言代码)浏览:1374 |
1054题解浏览:460 |
理财计划 (C语言代码)浏览:465 |
C语言训练-自守数问题 (C语言代码)浏览:739 |
神奇的fans (C语言代码)浏览:970 |
母牛的故事 (C语言代码)浏览:451 |
C语言程序设计教程(第三版)课后习题8.2 (C++代码)浏览:646 |
ET 2018-06-30 22:08:22 |
诈尸来回复,,因为我用getchar读入的,而不是scanf("%s",.....)末尾没有\0