The ispunct() function checks whether a character is a punctuation character or not.
The term “punctuation” as defined by this function includes all printable characters that are neither alphanumeric nor a space. For example ‘@’, ‘$’, etc.
This function is defined in ctype.h header file.
syntax:
int ispunct(int ch); ch: character to be checked. Return Value : function return nonzero if character is a punctuation character; otherwise zero is returned.
// Program to check punctuation #include <stdio.h> #include <ctype.h> int main() { // The puncuations in str are '!' and ',' char str[] = "welcome! to GeeksForGeeks, "; int i = 0, count = 0; while (str[i]) { if (ispunct(str[i])) count++; i++; } printf("Sentence contains %d punctuation" " characters.\n", count); return 0; } |
Output:
Sentence contains 2 punctuation characters.
// C program to print all Punctuations #include <stdio.h> #include <ctype.h> int main() { int i; printf("All punctuation characters in C" " programming are: \n"); for (i = 0; i <= 255; ++i) if (ispunct(i) != 0) printf("%c ", i); return 0; } |
Output:
All punctuation characters in C programming are:
! " # $ % & ' ( ) * +, - . / : ; ? @ [ \ ] ^ _ ` { | } ~
This article is contributed by Shivani Ghughtyal. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
Recommended Posts:
- How to call function within function in C or C++
- Write a one line C function to round floating point numbers
- Does C support function overloading?
- How can I return multiple values from a function?
- What is the purpose of a function prototype?
- How to declare a pointer to a function?
- C function to Swap strings
- Can we call an undeclared function in C++?
- What is evaluation order of function parameters in C?
- Can we use function on left side of an expression in C and C++?
- Function Pointer in C
- Importance of function prototype in C
- What happens when a function is called before its declaration in C?
- Default arguments and virtual function
- Function overloading and const keyword
- How to measure time taken by a function in C?
- Comparator function of qsort() in C
- Can we access private data members of a class without using a member or a friend function?
- Print substring of a given string without using any string function and loop in C
- How to print range of basic data types without any library function and constant in C?

