zoukankan      html  css  js  c++  java
  • getchar()解决“输入一行字符,分别统计出其中英文字母、空格、数字和其它字符的个数”

      getchar()函数的作用是从计算机终端(一般为键盘)获取一个无符号字符。getchar()函数只能接收一个字符,其函数值就是从输入设备获取到的字符。

    该函数声明在stdio.h头文件中,使用的时候要包含stdio.h头文件。

    如:

      #include<stdio.h>
      int getchar(void);
     例:

     1 #include "stdio.h" 2 main() {
     3     char c;   
     4     int letters=0,space=0,digit=0,others=0;  
     5     printf("please input some characters
    ");  
     6     while((c=getchar())!='
    ')  { 
     7         if(c>='a'&&c<='z'||c>='A'&&c<='Z')   letters++;  elseif(c=='')   space++;     
     8         elseif(c>='0'&&c<='9')        digit++;      
     9         else         others++;
    10     } 
    11     printf("all in all:char=%d space=%d digit=%d others=%d
    ",letters,         space,digit,others);
    12 }
    365个夜晚,我希望做到两天更一篇博客。加油,小白!
  • 相关阅读:
    POJ 1363
    HDU 1251(trie树)
    POJ 2081
    NYOJ 3(多边形重心)
    电子琴源码
    POJ 2503
    推荐些在线小制作小工具
    C# 在 webBrowser 光标处插入 html代码 .
    IIS自动安装程序(免费)
    developer express右键菜单显示汉化
  • 原文地址:https://www.cnblogs.com/qq2806933146xiaobai/p/12230544.html
Copyright © 2011-2022 走看看