#include <stdio.h>
int main(int argc, char **argv)
{
char ch;
int spaces= 0;//空格数
int lines= 0; //换行数
int characters = 0; //其他字符数
printf("输入:\n");
while(1)
{
scanf("%c", &ch);
if(ch == '#') //遇到'#'就结束循环
{
break;
}
if(ch == ' ') //遇到空格,space+1
{
spaces++;
}
else if(ch == '\n') //遇到换行,line+1
{
lines++;
}
else
{
characters++;
}
}
printf("spaces=%d, lines=%d,characters=%d\n",spaces,lines,characters);
return 0;
}
编写一个程序,该程序读取输入直到遇到#字符,然后报告读取的空格数目、读取的换行符数目以及读取 的所有其他字符数目。
最新推荐文章于 2023-11-01 22:14:43 发布