Code360 powered by Coding Ninjas X Naukri.com. Code360 powered by Coding Ninjas X Naukri.com
Table of contents
1.
Introduction
2.
Example
3.
Frequently Asked Questions
3.1.
What is C?
3.2.
What is the ispunct() function?
3.3.
What are punctuators?
3.4.
What are header files?
3.5.
What's the return value of the ispunct() function?
4.
Conclusion
Last Updated: Mar 27, 2024
Easy

ispunct() in C

Master Python: Predicting weather forecasts
Speaker
Ashwin Goyal
Product Manager @

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

Get the tech career you deserve, faster!
Connect with our expert counsellors to understand how to hack your way to success
User rating 4.7/5
1:1 doubt support
95% placement record
Akash Pal
Senior Software Engineer
326% Hike After Job Bootcamp
Himanshu Gusain
Programmer Analyst
32 LPA After Job Bootcamp
After Job
Bootcamp

Frequently Asked Questions

What is C?

C is a general-purpose programming language. C is commonly used in operating systems, device driver code, and protocol stacks.

What is the ispunct() function?

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.

What are punctuators?

Punctuators are characters that are neither alphanumeric nor a space. For example, ‘$’, and  ‘%’ are two of the punctuators.

What are header files?

Header files are a collection of pre-defined functions that are used to make the developer's programming experience more efficient and faster. Developers can import various header files using the include keyword in the C and C++ programming languages.

What's the return value of the ispunct() function?

The ispunct() function returns either 1 or 0. It returns one in case the character passed is a punctuator and returns 0 if the character is not a punctuator.

Conclusion

This blog covered all the necessary points about the ispunct() function in C programming. We further looked at two programs to understand the working of the ispunct() function. Do check out our blogs on object-oriented programming and data structures

Don’t stop here. check out Coding Ninjas for more unique courses and guided paths. Also, try Coding Ninjas Studio for more exciting articles, interview experiences, and fantastic Data Structures and Algorithms problems.

Previous article
strpbrk() in C
Next article
strspn() in C
Live masterclass