什麼是字元分析函式?使用 C 語言程式進行說明。
字元分析和轉換函式
“ctype.h”庫中的預定義函式用於分析字元輸入並轉換它們。
分析函式
序號 | 函式 | 描述 |
---|---|---|
1 | isalpha() | 字母 |
2 | isdigit() | 數字 |
3 | isspace() | 空格、換行符或製表符 |
4 | ispunct() | 特殊符號 |
5 | slower() | 小寫字母 |
6 | isupper() | 大寫字母 |
7 | isalphanumeric() | 字母/數字 |
轉換函式
函式 | 描述 |
---|---|
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
廣告