Home » C programs » ctype.h header file functions

ispunct() function of ctype.h in C

In this article, we are going to learn about the use ispunct() function of ctype.h header file in C language, and use it to check punctuation marks.
Submitted by Manu Jemini, on April 04, 2018

We can use a simple function to check a character if it’s punctuation or not. The Function is called ispunct( param a), which accepts a single parameter which defines a character.

There can be numerous cases when we can use this function like checking for the characters in the password or username. A lot of websites have checks on emails, usernames, passwords etc.

The ispunct() function returns true if the character is punctuation and false if character is not punctuation. This can be useful if you want to check for sql injections.

This function is from the ctype.h file which needs to be included in the program.

puncuation marks list/cheatsheet


ctype.h - ispunct() function Example in C

#include <stdio.h>
#include <ctype.h>
int main()
	// Defining the type of variables and initializing them
	char a='!';
	char b= 'M';
	// condition to prove that the value a is a punctuation mark
	if(ispunct(a)!= 0)
		printf("%c is a punctuation mark \n\n", a);
	// condition to prove that the value b is not a punctuation mark
	if(ispunct(b)== 0)
		printf("%c is not a punctuation mark \n\n", b);
	return 0;


ctype.h - ispunct()  in c language



Comments and Discussions



Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© some rights reserved.