《C Primer Plus(第5版)中文版》第7章编程练习第1题

来源:互联网 发布:新浪的股票数据接口 编辑:程序博客网 时间:2024/04/20 03:55

编写一个程序。该程序读取输入直到遇到#字符,然后报告读取的空格数目、读取的换行符数目以及读取的所有其他字符数目。

#include <stdio.h>int main(void){    char ch;    int space_c=0,enter_c=0,other=0;    while((ch=getchar())!='#'){        switch(ch){            case ' ':space_c++;break;            case '\n':enter_c++;break;            default:other++;break;        }    }    printf("Space:%d\nEnter:%d\nOther:%d\n",space_c,enter_c,other);    return 0;}
0 0