In this source code example, we will see how to use the isblank() function in C programming with an example.
isblank() Function Overview
The isblank() function determines if the given character is a blank character, which includes space (' ') or a horizontal tab ('\t').
Key Points:
- Requires the inclusion of the <ctype.h> header.
- The function accepts an int (typically a character) as its argument.
- It returns a non-zero value (true) if the character is blank; otherwise, it gives back 0 (false).
Source Code Example
#include <stdio.h>
#include <ctype.h>
int main() {
char ch;
printf("Enter a character: ");
scanf("%c", &ch);
if (isblank(ch))
printf("'%c' is a blank character.\n", ch);
else
printf("'%c' is not a blank character.\n", ch);
return 0;
}
Output
Enter a character: ' ' is a blank character.
Explanation
1. We begin by including the necessary header files: stdio.h for input/output functions and ctype.h for character functions.
2. Inside the main() function, we initialize a character variable named ch.
3. The user is prompted to enter a character.
4. The isblank() function is used to test if the provided character is a blank.
5. Depending on the function's result, the program prints a relevant message to the console.
Comments
Post a Comment