close

[C語言]統計輸入字元個數

標頭檔:

#include <stdio.h>
#include <conio.h>
#include <string.h>
#include <ctype.h>

 

//統計字元輸入個數
//BY UM
//Date 20140915
int main(void)
{

 
   char ch;
   int digit=0,upper=0,lower=0,cntrl=0,celse=0,punct=0;
   printf("\n");
   printf("判斷字元,輸入完後按ESC鍵離開\n");
   printf("============\n");
   do
   {
   printf("請輸入字元:");
   ch=getche();
   
   if(ch==27)
   {
    break;
    }
   else if (isdigit(ch))
   {
   digit+=1;
   }
   else if(isalpha(ch))
   {
     if(isupper(ch))
     {
      upper+=1;
     }        
     else
     {
      lower+=1;
     }       
   }
   else if(ispunct(ch))
   {
   punct+=1;   
   }
   else if(iscntrl(celse))
   {
   cntrl+=1;
   }
   else
   {
   
   celse+=1;
   
   }
   
   printf("\n");   
   }while(1);
   printf("\n\n");
  
   printf("0-9數字%d個 大寫字母%d個 小寫字母%d個 標點符號%d個 控制字元%d個 其他按鍵%d個",digit,upper,lower,punct,cntrl,celse);

 
 
     getch();
    return 0;
}

 

沒版權問題,題目練習自行撰寫。

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 UM程式研究日誌 的頭像
    UM程式研究日誌

    UM程式研究日誌

    UM程式研究日誌 發表在 痞客邦 留言(0) 人氣()