The ispunct() function defined in the ctype.h header file. It helps to check the specified character is a punctuation character or not. Punctuation characters are those who have any graphic characters but not have alphanumeric characters.
int ispunct(int argument); #where argument will be a character
The ispunct() function takes a single parameter and is in the form of an integer and the return value should be an integer. When a character is passed it is converted into the integer value corresponding to its ASCII value.
Parameter | Description | Required / Optional |
---|---|---|
argument | The character to be checked | Required |
If the given character is punctuation, ispunct() returns a non-zero integer else zero.When a punctuation character is passed we will get a different non-zero integer.
Input | Return Value |
---|---|
Zero | If the parameter isn't a punctuation |
Non zero number | If the parameter is a punctuation |
#include <stdio.h>
#include <ctype.h>
int main() {
char ch;
int output;
ch = ':';
output = ispunct(ch);
if (output == 0) {
printf("The given %c is not a punctuation", ch);
} else {
printf("The given %c is a punctuation", ch);
}
return 0;
}
Output:
The given : is a punctuation
#include <stdio.h>
#include <ctype.h>
int main()
{
int k;
printf("All punctuations in C: \n");
// Through all ASCII characters
for (k = 0; k <= 127; ++k)
if(ispunct(k)!= 0)
printf("%c ", k);
return 0;
Output:
All punctuations in C: ! " # $ % & ' ( ) * + , - . / : ; < = > ? @ [ \ ] ^ _ ` { | } ~