isalpha() function of ctype.h in C

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

The function is used to check if the character is an alphabet or not. If the character is an alphabet then the function returns zero and if not, then the function returns zero.

This function is rather simple and gives no information about the alphabet being lowercase or uppercase. For those cases you have to use a different function.

The Function can be easily implemented by checking for the ascii value of the character and then it will be same but with accurate results.

This function takes up a single character and returns an integer.

Example:

    Input character is: ‘a’
    Function will return 1


    Input character is: ‘@’
    Function will return 0

ctype.h - isalpha() function Example in C



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

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

	// assigning the value of variable
	a = 'A';
	b = '1';

	// condition to check the character
	if (isalpha(a) != 0)
	{
		printf("%c is an alphabet\n", a);
	}
	else
	{
		printf("%c is not an alphabet\n", a);
	}

	// condition to check the character
	if (isalpha(b) != 0)
	{
		printf("%c is a the alphabet\n", b);
	}
	else
	{
		printf("%c is not a the alphabet\n", b);
	}

	return 0;
}

Output

ctype.h - isalpha()  in c language



Comments and Discussions!

Load comments ↻





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