C语言入门 -- 读取英语语句 输出空格数、大小写及其他字符数目(2020/12/11)

读取英语语句

输出空格数、大小写及其他字符数目

编写一个程序,从键盘上读取一个英语语句,然后报告读取的空格数、读取的大写字符数、读取的小写字符数以及读取的所有其他字符数。

/*
  Name:programme3.c
  Author:祁麟
  copyright:BJTU | school of software 2004
  Date:2020/10/12 
  Description:reads an English statement from the keyboard and 
              then reports the number of spacesread, the number 
			  of percase characters read, the number of lowercase 
			  characters read, and the number of all other characters read.

*/

#include 

int main (){
     
	
	int space = 0 ;
	int uppercase = 0 ;
	int lowercase = 0 ;
	int other = -1 ;
	char aChar ;
	
	while ( aChar != '\n')
	{
     
	  	aChar = getchar();
		
		if ( aChar == ' '){
     
	  		space++;
		}
		else if ( aChar >='a' && aChar <='z'){
     
			lowercase++;
		}
		else if ( aChar >='A' && aChar <='Z'){
     
			uppercase++;
		}
		else{
     
			other++;
		}
	}	  
	printf ("space     %d\n",space);
	printf ("uppercase %d\n",uppercase);
	printf ("lowercase %d\n",lowercase);
	printf ("other     %d\n",other);
	
    return 0;	
}

你可能感兴趣的:(C语言入门,c语言)