什麼是字元分析函式?使用 C 語言程式進行說明。


字元分析和轉換函式

“ctype.h”庫中的預定義函式用於分析字元輸入並轉換它們。

分析函式

序號函式描述
1isalpha()字母
2isdigit()數字
3isspace()空格、換行符或製表符
4ispunct()特殊符號
5slower()小寫字母
6isupper()大寫字母
7isalphanumeric()字母/數字

轉換函式

函式描述
tolower()將大寫字母轉換為小寫字母
toupper()將小寫字母轉換為大寫字母

示例

讓我們透過一個程式瞭解字元分析和轉換函式 −

 線上演示

#include<stdio.h>
#include<ctype.h>
void main(){
   //Initializing compile time character variable//
char variable = 'A';
   //Reading User I/P//
   //printf("Enter the character : ");
   //scanf("%c",variable);
   //Using character analysis function & printing O/p//
   if (isalpha(variable)){
      printf("The character entered is :%c, an alphabet",variable);
   } else {
      printf("The character entered is not an alphabet");
   }
}

輸出

The character entered is :A, an alphabet

更新於: 2021 年 3 月 9 日

176 次瀏覽

開始 職業 生涯

完成課程後獲得認證

開始
廣告