การวิเคราะห์ตัวละครและฟังก์ชันการแปลง
ฟังก์ชันที่กำหนดไว้ล่วงหน้าในไลบรารี "ctype.h" ใช้สำหรับวิเคราะห์การป้อนอักขระและแปลงอักขระเหล่านั้น
ฟังก์ชันวิเคราะห์
| S.No | ฟังก์ชัน | คำอธิบาย |
|---|---|---|
| 1 | isalpha() | จะเป็นตัวอักษรหรือไม่ |
| 2 | isdigit() | ตัวเลขหรือไม่ |
| 3 | isspace() | เว้นวรรค ขึ้นบรรทัดใหม่หรือแท็บ |
| 4 | ispunct() | สัญลักษณ์พิเศษหรือไม่ |
| 5 | slower() | ตัวพิมพ์เล็กของตัวอักษร |
| 6 | isupper() | ตัวพิมพ์ใหญ่ของตัวอักษร |
| 7 | isalphanumeric() | เป็นตัวอักษร/ตัวเลขหรือไม่ |
การแปลงฟังก์ชัน
| ฟังก์ชัน | คำอธิบาย |
|---|---|
| tolower() | แปลงอักษรตัวพิมพ์ใหญ่เป็นตัวพิมพ์เล็ก |
| ท็อปเปอร์() | แปลงอักษรตัวพิมพ์เล็กเป็นตัวพิมพ์ใหญ่ |
ตัวอย่าง
ให้เราดูโปรแกรมสาธิตการวิเคราะห์อักขระและฟังก์ชันการแปลง -
#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