/*1.编写一个程序。该程序读取输入直到遇到#字符,然后报告读取的空格数目、读取的换行符数目以及读取的所有其他字符数目。*/
#include<stdio.h>
#include<stdlib.h>
#define STOP '#'
int main()
{
char a;
int space = 0, enter = 0, others = 0;
printf("Please input:");
while ((a = getchar()) != STOP)
{
if (a == ' ')
space++;
else if (a == '\n')
enter++;
else others++;
}
printf("%dspaces %denters %dothers\n", space, enter, others);
system("pause");
return 0;
}
C Primer Plus7-1
字符计数程序
最新推荐文章于 2024-09-28 21:40:24 发布
本文介绍了一个简单的C语言程序,该程序能够读取用户输入直至遇到特定终止符,并统计输入中的空格、换行符以及其他字符的数量。
236

被折叠的 条评论
为什么被折叠?



