There are two types of functions in C-Language:
Functions to input a single character are available in 'stdio.h' header file. These functions are:
Example 2: Input Character and display it.
#include<stdio.h> #include<conio.h> void main() { char a; clrscr(); printf("Enter character: "); a = getch(); //a = getche(); //a = getchar(); printf("\nYou have pressed: %c",a); //putch(a); //putchar(a); //Output of putch and putchar is same getch(); }
Example 3: Program to explain difference between getch() and getche() function.
void main() { char ch; clrscr(); printf("Enter character: "); ch=getch(); printf("\nch=%c",ch); printf("\nEnter character: "); ch=getche(); printf("\nch=%c",ch); getch(); }
C Character functions are used to identify whether the input character is alphabet, digit, lowercase, uppercase etc.
S.No | Character Function | Description |
---|---|---|
isalpha() | Return true if character is an alphabet or not. | |
isdigit() | Return true if character is a digit or not. | |
isalnum() | Return true if character is an alphabet, number or not. | |
islower() | Return true if character is in lowercase or not. | |
isupper() | Return true if character is in uppercase or not. | |
isspace() | Return true if character is a space or not. | |
ispunct() | Return true if character is punctuation or not. |
Example 4: WAP to check whether the given character is Alpha-numeric or not.
void main() { char ch; clrscr(); printf("Enter character: "); ch=getche(); if(isalnum(ch)) printf("\nIt is alpha-numeric character."); else printf("\nIt is not an alpha-numeric character."); getch(); }
Example 5: WAP to check whether the given character is Alphabet or not.
void main() { char ch; clrscr(); printf("Enter character: "); ch=getche(); if(isalpha(ch)) printf("\nIt is a alphabet character."); else printf("\nIt is not an alphabet character."); getch(); }