isalpha() function in CThis section will discuss the isalpha() function of the C programming language. The islpha() function is a predefined library function of the ctype.h header file that takes an argument as the character type and validates for valid alphabets. If the given character is alphabets (a - z or A to Z), it returns a non-zero value; else, it returns 0. Note: While using the islpha() function, we must add the ctype.h header file in our program.For example, if the given character is from 'a' to 'z' and 'A' to 'Z', the isalpha() function returns a non-zero value. And if the given character is not the letters of the alphabets, it returns zeroes for other characters ( '@', '$', '&', etc.). Syntax of the isalpha functionFollowing is the syntax for the isalpha() function in C programming, as follows. Here, the isalpha() function takes ch as the character type argument to check the alphabetic letters. Parameters:Ch: It represents the character type variable to be checked. Return Value:The isalpha() function returns a non zero value when the 'ch' character is an alphabetic. Else, it shows the zero. Example 1: Program to check the alphabetic character using the islpha() function Let's consider an example to check whether the given character is alphabet using the islpha() function in the C programming. Output: 'a' is a valid alphabetic character. '&' is not a valid alphabetic character. Example 2: Program to validate the given character using the isalpha() function Let's consider a example to use the isalpha() function and check whether the various given character is alphabets or not in the C programming. Output: 'e' is an alphabetic character. 'Z' is an alphabetic character. '@' is not an alphabetic character. '5' is not an alphabetic character. Example 3: Program to get a character from user and check whether the character is valid character Let's consider an example to check valid characters using the isalpha function in C programming language. Output: Enter a valid character: g You entered a valid alphabet. In the above program, we take the 'g' character from the user and then use the isalpha() function to check whether the input character is an alphabet or not. If the character is an alphabet, it prints "You entered a valid character". 2nd execution: In the second execution, we input the '$' character and use the isalpha() function to check the character is an alphabet or not. Here '$' character is not an alphabet. So, it returns the "$ is not an alphabet. Please, enter a valid alphabet character ('a' to 'z' or 'A' to 'Z')". Example 4: Program to return a non zeroes values for alphabetic character using the isalpha() function Let's consider an example to validate the alphabetic character and returns a non zero values using the isalpha() function in the C programming language. Output: The result of valid uppercase alphabetic character is passed: 1 The result of valid lowercase alphabetic character is passed: 2 The result of non-alphabetic character is passed: 0 In the above program, we get different non-zero values when the alphabetic character is passed to the isalpha() function. But, when we pass the non-alphabetic character to the isalpha() function, it always returns 0. Example 5: Program to check all valid characters of the array using the isalpha() function Let's create an example to use the isalpha function to check the array character in C programming language. Output: '*' is NOT an Alphabetic character. '$' is NOT an Alphabetic character. '@' is NOT an Alphabetic character. '7' is NOT an Alphabetic character. 'Z' is an Alphabetic character. 'p' is an Alphabetic character. '!' is NOT an Alphabetic character. Next TopicBisection Method in C |