ADVERTISEMENT
ADVERTISEMENT

Home » C programs » ctype.h header file functions

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
ADVERTISEMENT

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

ADVERTISEMENT



ADVERTISEMENT



Comments and Discussions


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.