
- C Programming Tutorial
- C - Home
- C - Overview
- C - Environment Setup
- C - Program Structure
- C - Basic Syntax
- C - Data Types
- C - Variables
- C - Constants
- C - Storage Classes
- C - Operators
- C - Decision Making
- C - Loops
- C - Functions
- C - Scope Rules
- C - Arrays
- C - Pointers
- C - Strings
- C - Structures
- C - Unions
- C - Bit Fields
- C - Typedef
- C - Input & Output
- C - File I/O
- C - Preprocessors
- C - Header Files
- C - Type Casting
- C - Error Handling
- C - Recursion
- C - Variable Arguments
- C - Memory Management
- C - Command Line Arguments
- C Programming useful Resources
- C - Questions & Answers
- C - Quick Guide
- C - Useful Resources
- C - Discussion
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.
- Related Articles
- C Program to check the type of character entered
- Unit Testing for C# Code
- Type difference of character literals in C vs C++
- Type difference of character literals in C and C++
- Data type of character constants in C and C++
- C++ Program for sorting variables of any data type
- How MySQL reacts when we specify a CHARACTER SET binary attribute for a character string data type?
- C# Program to Convert Character case
- C# Program to check if a character is a whitespace character
- C# program to count the occurrences of each character
- What is Storage Testing Tutorial with Type & Concepts?
- Python program for removing nth character from a string
- C++ Program to find the Shortest Distance to a character
- C++ Program to find out the health of a character
- Python program for removing n-th character from a string?

Advertisements