Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> การเขียนโปรแกรม C

isblank() ใน C/C++

isblank() ตรวจสอบ character (char) ว่าเป็น blank (space หรือ tab \t) หรือไม่ ประกาศใน ctype.h (C) หรือ cctype (C++)

ไวยากรณ์

int isblank(int char);

ตัวอย่าง

#include <ctype.h>
#include <iostream>
using namespace std;
int main() {
    string s = "The space between words. ";
    int i = 0, 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

นับช่องว่างใน "The space between words. " ได้ 4 ช่อง (อาจต่างจาก iswblank เพราะ string ต่างกัน)