Introduction
C is a general-purpose programming language. C is commonly used in operating systems, device driver code, and protocol stacks. The C programming language is not to be confused with the C++ programming language, which is an extension of the C programming language.
The ispunct() function is present in the ctype.h header file of the C language and is used to check whether a given character is a punctuator or not. Punctuators are characters that are neither alphanumeric nor a space. For example, ‘$’ and ‘%’ are two of the punctuators.
Also see : C Static Function, and Tribonacci Series
Must Read Passing Arrays to Function in C
Example
Let us look at an example two printout all the punctuators present in C,
#include <stdio.h>
#include <ctype.h>
int main()
{
int i;
printf("\n\nPunctuators in C are: \n");
for (i = 0; i <= 255; ++i)
if (ispunct(i) != 0)
printf("%c ", i);
printf("\n\n\n");
return 0;
}
Let us look at one more example to count the number of punctuators present in a given sentence,
#include <stdio.h>
#include <ctype.h>
int main()
{
char str[] = "Hey, coder! Welcome to CodingNinjas!!";
printf("%s\n", str);
int i = 0, count = 0;
while (str[i]) {
if (ispunct(str[i]))
count++;
i++;
}
printf("There are %d punctuators in the sentence\n", count);
return 0;
}
You can also read about the dynamic arrays in c and Short int in C Programming
Must Read what is storage class in c and Decision Making in C