- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
C program for testing the character type
There are some predefined functions available in "ctype.h" library for analyzing the character input and converting them.
Analysis Functions
The character analysis functions are listed below −
Function | Checks whether entered character is |
---|---|
isalpha | An alphabet (or) not |
isdigit | A digit (or) not |
isspace Q | A space, a newline (or) tab |
ispunct ( | A special symbol (or) not |
islower | A lower case letter of alphabet |
isupper Q | An upper case letter of alphabet |
isalphanumeric | An alphabet/digit or not |
Converting Functions
The converting functions are listed below −
Function | Conversion |
---|---|
tolower() | Converts an upper case alphabet to lower case |
toupper Q | Converts a lower case alphabet to upper case |
Program
Following is the C program for character analysis and conversion functions which are used to test the character type −
#include <stdio.h> #include <ctype.h> main(){ char character; printf("Press any key digit or alphabet
"); character = getchar(); if (isalpha(character) > 0) printf("The character is a letter."); else if (isdigit (character) > 0) printf("The character is a digit."); else printf("The character is not alphanumeric."); }
Output
When the above program is executed, it produces the following result −
Run 1: Press any key digit or alphabet 3 The character is a digit. Run 2: Press any key digit or alphabet G The character is a letter. Run 3: Press any key digit or alphabet & The character is not alphanumeric.
Advertisements