ฟังก์ชัน isblank() ใช้เพื่อตรวจสอบว่าอักขระที่ส่งผ่านเป็นค่าว่างหรือไม่ โดยพื้นฐานแล้วจะเป็นอักขระเว้นวรรคและพิจารณาอักขระแท็บด้วย (\t) ฟังก์ชันนี้ประกาศในไฟล์ส่วนหัว "ctype.h" ในภาษา C และไฟล์ส่วนหัว "cctype"" ในภาษา C++
นี่คือไวยากรณ์ของ isblank() ในภาษา C++
int isblank(int char);
นี่คือตัวอย่าง isblank() ในภาษา C++
ตัวอย่าง
#include <ctype.h>
#include <iostream>
using namespace std;
int main() {
string s = "The space between words. ";
int i = 0;
int count = 0;
while(s[i]) {
char c = s[i++];
if (isblank(c)) {
count++;
}
}
cout << "\nNumber of blanks in sentence : " << count << endl;
return 0;
} ผลลัพธ์
Number of blanks in sentence : 4
ในโปรแกรมข้างต้น สตริงจะถูกส่งผ่านในตัวแปร s ฟังก์ชัน isblank() ใช้เพื่อตรวจสอบช่องว่างหรือช่องว่างในสตริงที่ส่งผ่าน ดังแสดงในตัวอย่างโค้ดต่อไปนี้
string s = "The space between words. ";
int i = 0;
int count = 0;
while(s[i]) {
char c = s[i++];
if (isblank(c)) {
count++;
}
}