The function prototype of ispunct()
is:
int ispunct(int argument);
If a character passed to the ispunct()
function is a punctuation, it returns a non-zero integer. If not, it returns 0.
In C programming, characters are treated as integers internally. That's why ispunct()
takes an integer argument.
The ispunct()
function is defined in the ctype.h header file.
Example 1: Program to check punctuation
#include <stdio.h>
#include <ctype.h>
int main() {
char c;
int result;
c = ':';
result = ispunct(c);
if (result == 0) {
printf("%c is not a punctuation", c);
} else {
printf("%c is a punctuation", c);
}
return 0;
}
Output
: is a punctuation
Example 2: Print all Punctuations
#include <stdio.h>
#include <ctype.h>
int main()
{
int i;
printf("All punctuations in C: \n");
// looping through all ASCII characters
for (i = 0; i <= 127; ++i)
if(ispunct(i)!= 0)
printf("%c ", i);
return 0;
}
Output
All punctuations in C: ! " # $ % & ' ( ) * + , - . / : ; < = > ? @ [ \ ] ^ _ ` { | } ~