题目: 编写一个程序。该程序读取输入直到遇到#字符,然后报告读取的空格数目、读取的换行符数目以及读取的所有其他字符数目。
/**< 该程序读取输入直到遇到#字符,然后报告读取的空格数目、
读取的换行符数目以及读取的所有其他字符数目 */
#include <stdio.h>
#include <stdlib.h>
int main()
{
int blank = 0;
int newline = 0;
int others = 0;
char c;
while((c = getchar()) != '#')
{
if(c == ' ')
{
blank++;
}
else if(c == '\n')
{
newline++;
}
else others++;
}
printf("blank=%d, newline=%d, others=%d\n",blank, newline, others);
return 0;
}
运行结果: