What is ispunct() in C?

The ispunct() function checks whether or not the character passed to it is a punctuation character.

%0 node_1623042748416 ! node_1 " node_2 # node_3 $ node_1623042735181 % node_1623042783230 &
%0 node_1623042772839 ' node_1623042785160 ( node_1623042748416 ) node_1 * node_2 + node_3 , node_1623042735181 -
%0 node_1623042772839 . node_1623042785160 / node_1623042748416 : node_1 ; node_2 < node_3 =
%0 node_1623042772839 > node_1623042785160 ? node_1623042748416 @ node_1 [ node_2 \ node_3 ] node_1623042846996 ^
%0 node_1623042772839 _ node_1623042785160 ` node_1623042748416 { node_1 | node_2 } node_3 ~
Punctuation characters in C

Library

#include<ctype.h>

Declaration

Following is the declaration of ispunct() in C, where c is the character to be checked:

int ispunct(int c);

Return value

The function returns an integer value.

If the integer returned is non-zero (true), it means c is a punctuation character.

If the integer returned is zero (false), it means c is not a punctuation character.

Code

#include <stdio.h>
#include <ctype.h>
int main()
{
//first 5 characters are punctuation characters
char ch[] = {'$', '>', '@', '[', ',' ,' ', '\r', 'a', 'Z', '7'};
int i = 0;
while (i < 10) {
if(ispunct(ch[i]))
printf("Punctuation character.\n", ch[i]);
else
printf("Not a punctuation character.\n", ch[i]);
++i;
}
return 0;
}

Free Resources

Copyright ©2025 Educative, Inc. All rights reserved