C C++ Java Data Structure Python JavaScript CSS Ajax PL/SQL PHP Puzzles C programs C++ programs Java programs



Home » C programs » ctype.h header file functions

isspace() function of ctype.h in C






In this article, we are going to learn about the isspace() function of ctype.h header file in C programming language, and use it to identify the space characters.
Submitted by Abhishek Sharma, on April 10, 2018

This function takes a parameter of a character and checks if the character is a space character or not. The function returns zero if the character is not a space character and ‘one’ if the character is a space character.

Using this function is rather simple because all it takes is a character of type char and returns an integer. The Value of integer determines if the character is a space character or not.

This function can be used to identify the space characters in the array of characters or user’s input at a certain point.

Example:

    Input character is: 'a'
    Function will return 0


    Input character is: ' '
    Function will return 1



ctype.h - isspace() function Example in C

#include <stdio.h>
#include <ctype.h>

int main()
{
	// defining the type of variable
	char a,b;

	// assigning the value of variables
	a = 'A';
	b = '\n';

	// condition to test the space characters
	if (isspace(a) != 0)
	{
		printf("%c is a space character\n\n", a);
	}
	else
	{
		printf("%c is not a space character\n\n", a);
	}

	if (isspace(b) != 0)
	{
		printf("Value of b is a space character\n");
	}
	else
	{
		printf("Value of b is not a space character\n");
	}

	return 0;
}

Output

ctype.h - isspace()  in c language







You may also be interested in...

C/C++ Tips and Tricks...

Was this page helpful? YES NO

Are you a blogger? Join our Blogging forum.


Comments and Discussions