How to use isspace() function in C?

The below example demonstrates how to use the isspace() function in C language:

C




// C program to illustrate the syntax of isspace function
#include <ctype.h>
#include <stdio.h>
  
int main()
{
    // declaring a char variable to be tested
    char ch1 = ' ';
    char ch2 = 'a';
  
    // checking ch1
    if (isspace(ch1))
        printf("Entered character is space\n");
    else
        printf("Entered character %c is not space", ch1);
  
    // checking ch2
    if (isspace(ch2))
        printf("Entered character is space\n");
    else
        printf("Entered character %c is not space\n", ch2);
  
    return 0;
}


Output

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

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.

Similar Reads

Syntax of isspace()

isspace (character);...

How to use isspace() function in C?

The below example demonstrates how to use the isspace() function in C language:...

Examples of isspace() function in C

...

Conclusion

Example 1: C Program to count the number of words in a string....

FAQs on C isspace() Function

...

Contact Us