![]() |
VOOZH | about |
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.
isspace (character);
The isspace() function takes only one parameter of type char. It is the character to be tested.
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:
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:
Character | Name |
|---|---|
' ' | Space |
'\t' | Horizontal Tab |
'\n' | Newline |
'\v' | Vertical Tab |
'\f' | Feed |
'\r' | Carriage Return |
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.