Home »
C programs »
ctype.h header file functions
ispunct() function of ctype.h in C
In this article, we are going to learn about the use ispunct() function of ctype.h header file in C language, and use it to check punctuation marks.
Submitted by Manu Jemini, on April 04, 2018
We can use a simple function to check a character if it’s punctuation or not. The Function is called ispunct( param a), which accepts a single parameter which defines a character.
There can be numerous cases when we can use this function like checking for the characters in the password or username. A lot of websites have checks on emails, usernames, passwords etc.
The ispunct() function returns true if the character is punctuation and false if character is not punctuation. This can be useful if you want to check for sql injections.
This function is from the ctype.h file which needs to be included in the program.
ctype.h - ispunct() function Example in C
#include <stdio.h>
#include <ctype.h>
int main()
{
// Defining the type of variables and initializing them
char a='!';
char b= 'M';
// condition to prove that the value a is a punctuation mark
if(ispunct(a)!= 0)
{
printf("%c is a punctuation mark \n\n", a);
}
// condition to prove that the value b is not a punctuation mark
if(ispunct(b)== 0)
{
printf("%c is not a punctuation mark \n\n", b);
}
return 0;
}
Output