Wanted to know if there is any inbuilt function in C to check for special characters like space, tab just like the isdigit()
function?
Asked
Active
Viewed 244 times
-4

Jonathan Leffler
- 730,956
- 141
- 904
- 1,278

Nikitha niki
- 3
- 1
-
2There's a [whole set of isxxxxx character functions in the C library](https://en.cppreference.com/w/c/string/byte/isalnum) if you take the time to look. If what you want isn't there, then write one that does what you want. You're *probably* interested in `isspace`. – WhozCraig May 30 '19 at 01:37
-
1Re your question tags: I recommend reading [Understanding the Differences Between C#, C++, and C](https://csharp-station.com/understanding-the-differences-between-c-c-and-c/). – ProgrammingLlama May 30 '19 at 01:38
-
Possible duplicate of [Using C isdigit for error checking](https://stackoverflow.com/questions/6528628/using-c-isdigit-for-error-checking) – Kir Chou May 30 '19 at 02:55
-
Possible duplicate of [How to check if a string is a letter(a-z or A-Z) in c](https://stackoverflow.com/questions/19896645/how-to-check-if-a-string-is-a-lettera-z-or-a-z-in-c) – user4098326 May 30 '19 at 03:00
-
Neither of the proposed duplicates is remotely appropriate as a duplicate. It won't be surprising to find that there is a duplicate. However, neither of those is the right duplicate. – Jonathan Leffler May 30 '19 at 03:42
1 Answers
1
Look up and learn the functions defined by the C11 standard in the §7.4 Character handling <ctype.h>
functions.
The isspace()
function looks for a fairly general set of white space characters:
' ', '\t', '\r', '\f', '\n', '\v'
The isblank()
function looks for the set you want:
' ', '\t'
To some extent, the POSIX variants are locale dependent — the POSIX specifications for isspace()
and isblank()
are less emphatic about which characters are matched, but disclaim conflict with the C standard, so in the C locale, the behaviour is as required by the C standard.

Jonathan Leffler
- 730,956
- 141
- 904
- 1,278