isalpha(c) is a function in C which can be used to check if the passed character is an alphabet or not. It returns a non-zero value if it’s an alphabet else it returns 0. For example, it returns non-zero values for ‘a’ to ‘z’ and ‘A’ to ‘Z’ and zeroes for other characters.
Similarly, isdigit(c) is a function in C which can be used to check if the passed character is a digit or not. It returns a non-zero value if it’s a digit else it returns 0. For example, it returns a non-zero value for ‘0’ to ‘9’ and zero for others.
Avoiding common errors : It is important to note this article does not cover strings! Only Cstrings. Cstrings are an array of single characters (char) in their behaviour. There are advantages and disadvantages to this.
Example Problem : Given a cstring str, find the number of alphabetic letters and number of decimal digits in that cstring.
Input: 12abc12 Output: Alphabetic_letters = 3, Decimal_digits = 4 Input: 123 GeeksForGeeks is Number 1 Output: Alphabetic_letters = 21, Decimal_digits = 4
Explanation And Approach:
Alphabetic_letters = 3, Decimal_digits = 4
This article is contributed by Mazhar Imam Khan. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- strtok() and strtok_r() functions in C with examples
- asctime() and asctime_s() functions in C with Examples
- Commonly used String functions in C/C++ with Examples
- Methods vs. Functions in C++ with Examples
- Write one line functions for strcat() and strcmp()
- Functions that are executed before and after main() in C
- fill() and fill_n() functions in C++ STL
- Forward List in C++ | Set 1 (Introduction and Important Functions)
- strdup() and strndup() functions in C/C++
- Binary Search functions in C++ STL (binary_search, lower_bound and upper_bound)
- Ceil and Floor functions in C++
- Pure Virtual Functions and Abstract Classes in C++
- Wide char and library functions in C++
- Find and print duplicate words in std::vector<string> using STL functions
- asin() and atan() functions in C/C++ with Example
- Explicitly Defaulted and Deleted Functions in C++ 11
- atol(), atoll() and atof() functions in C/C++
- beta(), betaf() and betal() functions in C++ STL
- std::legendre, std::legendref and std::legendrel functions in C++17
- Virtual Functions and Runtime Polymorphism in C++ | Set 1 (Introduction)
Improved By : BrenlyDrake