7.12 编程练习题1

来源:互联网 发布:免费的数据恢复app 编辑:程序博客网 时间:2024/05/20 10:13
/*1.编写一个程序读取输入,读到#字符停止,然后报告读取的空格数,换行符数和其他所有字符的数量*/
#include <stdio.h>#include<string.h>                                    //getchar()头文件int main (void){char ch;int kgs = 0;int hhf = 0;int qtz = 0;printf("Please enter some char to total:\n"); //提示用户输入while ((ch = getchar())!='#'){if(ch == ' ')kgs++;else if(ch == '\n')hhf++;elseqtz++;}printf ("spaces: %d, newlines: %d, other: %d\n", kgs, hhf, qtz);return 0;}

0 0