isspace() in C
The isspace() in C is a predefined function used for string and character handling. This function is used to check if the argument contains any whitespace characters. It is declared inside <ctype.h> header file.
Syntax of isspace()
Parameters of isspace()
The isspace() function takes only one parameter of type char. It is the character to be tested.
Return Value of isspace()
The isspace() function returns an integer value that tells whether the passed parameter is a whitespace character or not. The possible return values of isspace() function are:
- If the character is a whitespace character, then the return value is non-zero.
- If the character is not a whitespace character, then the return value is zero.
How to use isspace() function in C?
The below example demonstrates how to use the isspace() function in C language:
Entered character is space Entered character a is not space
The space is not the only whitespace character in the C language. There are more whitespace characters which are as follows:
Examples of isspace() function in C
Example 1: C Program to count the number of words in a string.
The logic of this program is that the two words in a sentence are separated by a whitespace character. So we need to count the number of whitespace characters.
Number of words in the sentence is : 3
The isspace() function is useful in cases when we want to process strings or characters. For example, in the word counter, we can calculate the number of words by counting whitespace and few other symbols.
FAQs on C isspace() Function
1. What is the function prototype of the isspace() function?
The function prototype of isspace() in C is:
int isspace(int _C);
2. What is the use of isspace() function in C?
It is used to check whether the given character is whitespace or not.
3. Which header file is used to import the isspace() function in C?
The isspace() function is defined inside the <ctype.h> header file. So, we need to include <ctype.h> header file to use isspace() function in our program.
4. How isspace() function works?
The isspace() function in C works by comparing the ASCII values of the character and if it matches then returns a non-zero value, otherwise zero is returned.
Please Login to comment...