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



Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.