ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT

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
ADVERTISEMENT

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

ADVERTISEMENT



ADVERTISEMENT



Comments and Discussions

ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.