Standard library functions
- We will see some standard library functions, which works on characters.
- This Functions operates on characters
- For using this functions ,We have to specify the header file #include<ctype.h>
Functions and their description.
Function | Description | |||
---|---|---|---|---|
isdigit(c) | Tells character 'c' is digit or not. | |||
isalpha(c) | Tells character 'c' is a alphabet or not | |||
isalnum(c) | Tells character 'c' is a alphnumeric or not | |||
isspace(c) | Tells character 'c' is a space or not | |||
islower(c) | Tells character 'c' is a small letter character or not | |||
isupper(c) | Tells character 'c' is a Capital letter or not | |||
ispunct(c) | Tells character 'c' is a punctuation symbol or not | |||
tolower(c) | Converts the uppercase letter to lowercase letter | |||
toupper(c) | Converts the lowercase letter to uppercase letter. | |||
isascii(c) | Tells character 'c' is a ascii character or not | |||
isprint(c) | Tells character 'c' is a printable on screen or not |
Lets make a menu driven program to understand all this above listed functions.
#include<stdio.h>
#include<ctype.h>
void main()
{
int choice;
char c;
printf("enter the character:");
scanf("%c",&c);
printf("\nWhat you want to check?");
printf("\n1:alphabet or Not");
printf("\n2:digit or Not");
printf("\n3:Punctuation Symbol or Not");
printf("\n4 :Capital letter or small letter");
//taking input from the user.
printf("\nenter your choice");
scanf("%d",&choice);
//switching the choice variable
switch(choice)
{
case 1: //if choice is 1 then case will get executed.
if(isalpha(c) == 1) //if this function return 1 then the character is a alphabet otherwise it's not.
printf("\n%c is a alphabet.",c);
else
printf("\n%c is not an alphabet.",c);
break;
case 2://if choice is 2 then case will get executed.
if(isdigit(c)==1) //if this function return 1 then the character is a digit otherwise it's not.
printf("\n%c is a digit.",c);
else
printf("\n%c is not an digit.",c);
break;
case 3://if choice is 3 then case will get executed.
if(ispunct(c)==1) //if this function return 1 then the character is a symbol otherwise it's not.
printf("\n%c is a Punctuation Symbol.",c);
else
printf("\n%c is not an Punctuation Symbol.",c);
break;
case 4://if choice is 4 then case will get executed.
if(isupper(c)==1) //if this function return 1 then the character is a uppercase letter otherwise it's lowercase letter.
printf("\n%c is a uppercase letter.",c);
if(islower(c)==1)
printf("\n%c is a lowercase letter.",c);
break;
default:
printf("\nInvalid choice!");
break;
}
}
#include<stdio.h> #include<ctype.h> void main() { int choice; char c; printf("enter the character:"); scanf("%c",&c); printf("\nWhat you want to check?"); printf("\n1:alphabet or Not"); printf("\n2:digit or Not"); printf("\n3:Punctuation Symbol or Not"); printf("\n4 :Capital letter or small letter"); //taking input from the user. printf("\nenter your choice"); scanf("%d",&choice); //switching the choice variable switch(choice) { case 1: //if choice is 1 then case will get executed. if(isalpha(c) == 1) //if this function return 1 then the character is a alphabet otherwise it's not. printf("\n%c is a alphabet.",c); else printf("\n%c is not an alphabet.",c); break; case 2://if choice is 2 then case will get executed. if(isdigit(c)==1) //if this function return 1 then the character is a digit otherwise it's not. printf("\n%c is a digit.",c); else printf("\n%c is not an digit.",c); break; case 3://if choice is 3 then case will get executed. if(ispunct(c)==1) //if this function return 1 then the character is a symbol otherwise it's not. printf("\n%c is a Punctuation Symbol.",c); else printf("\n%c is not an Punctuation Symbol.",c); break; case 4://if choice is 4 then case will get executed. if(isupper(c)==1) //if this function return 1 then the character is a uppercase letter otherwise it's lowercase letter. printf("\n%c is a uppercase letter.",c); if(islower(c)==1) printf("\n%c is a lowercase letter.",c); break; default: printf("\nInvalid choice!"); break; } }
Output for Each choice:
Ouput1:
enter the character : A
What you want to check?");
1:alphabet or Not
2:digit or Not
3:Punctuation Symbol or Not"
4 :Capital letter or small letter
enter your choice:1
A is a alphabet.
What you want to check?");
1:alphabet or Not
2:digit or Not
3:Punctuation Symbol or Not"
4 :Capital letter or small letter
enter your choice:1
A is a alphabet.
Ouput2:
enter the character:1
What you want to check?");
1:alphabet or Not
2:digit or Not
3:Punctuation Symbol or Not"
4 :Capital letter or small letter
enter your choice:2
1 is a digit.
What you want to check?");
1:alphabet or Not
2:digit or Not
3:Punctuation Symbol or Not"
4 :Capital letter or small letter
enter your choice:2
1 is a digit.
Ouput3:
enter the character:1
What you want to check?");
1:alphabet or Not
2:digit or Not
3:Punctuation Symbol or Not"
4 :Capital letter or small letter
enter your choice:3
@ is a Punctuation Symbol.
What you want to check?");
1:alphabet or Not
2:digit or Not
3:Punctuation Symbol or Not"
4 :Capital letter or small letter
enter your choice:3
@ is a Punctuation Symbol.
Ouput4:
enter the character: a
What you want to check?");
1:alphabet or Not
2:digit or Not
3:Punctuation Symbol or Not"
4 :Capital letter or small letter
enter your choice:4
a is a lowercase letter.
What you want to check?");
1:alphabet or Not
2:digit or Not
3:Punctuation Symbol or Not"
4 :Capital letter or small letter
enter your choice:4
a is a lowercase letter.
Ouput5:
enter the character: B
What you want to check?");
1:alphabet or Not
2:digit or Not
3:Punctuation Symbol or Not"
4 :Capital letter or small letter
enter your choice:4
B is a uppercase letter.
What you want to check?");
1:alphabet or Not
2:digit or Not
3:Punctuation Symbol or Not"
4 :Capital letter or small letter
enter your choice:4
B is a uppercase letter.
Further Concepts:
Further Topics:
- Functions In C
- Why Functions?
- What are Functions?
- how to write our functions?
- What are programmer define functions?
- How to declare function?
- How to define a function?
- What is function Prototype?
- how to declare a function?
- what are Actual Parameters?
- What are Formal Parameters?
- Function Call?
- how to call a Function?
- What are different types of calling function?
- Call by value
- call by reference
- Recursion
- Array and Functions
- How to pass an array to a function?
- Practice programs
People Also Searched:
- what are various string handling functions
- Functions from #include<string.h> Header File
- what are strcpy(), strcmp(), strncmp(), strcmpi(),etc
- strcmp() VS strncmp() VS strcmpi()
- Input And Output Functions
- How to take strings As Input
- What is gets() functions
- What is puts() functions
- What is Character array
- Strings In C
- Concept of strings
- Concept of Initializing One Dimensional Array
- How to take array elements as input from the User
- How to declare 1D Array?
- How to Initialize 1D Array?
- What are Array?
- Need Of Array
- Why Array?
- Concept of Array
1 Comments
Hey I have read your article it is nice. Please do read my article.
ReplyDeletePost a Comment