/*輸出一行字符,分類統計字符個數*/
#include<stdio.h>
#include<stdlib.h>
int main(void)
{
int letter=0,space=0,digit=0,other=0;/*定義變量並初始化*/
char c;/*定義字符串c*/
printf("請輸入一行字符,以回車鍵結束\n");
while((c=getchar())!='\n')/*判斷c是否是回車鍵*/
if(c>='a'&&c<='z'||c>='A'&&c<='Z')/*判斷c是否是字母*/
letter++;/*計算字母個數*/
else if(c==' ')/*判斷c是否是空格*/
space++;/*計算空格個數*/
else if(c>='0'&&c<='9')/*判斷c是否是數字*/
digit++;/*計算數字個數*/
else
other++;/*計算其他字符個數*/
printf("letter=%d,space=%d,digit=%d,other=%d\n",letter,space,digit,other);
system("PAUSE");
return 0;
} /*end main*/

