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\n");  
 6     while((c=getchar())!='\n')  { 
 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\n",letters,         space,digit,others);
12 }

 

相关文章:

  • 2021-08-04
  • 2021-12-13
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-12
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-01-02
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案