C program to print all punctuation marks using the ispunct() function

Here, we are going to learn how to print all punctuation marks using the ispunct() function in C language?
Submitted by Nidhi, on August 25, 2021

Problem statement

Here, we will print all punctuation marks available in C language using the ispunct() function.

The ispunct() function checks whether a character is a punctuation character or not. This function is defined in ctype.h header file.

Syntax:

int ispunct(int ch);

The function accepts a character and returns nonzero if the character is a punctuation character; zero, otherwise.

Program

The source code to print all punctuation marks using the ispunct() function is given below. The given program is compiled and executed using GCC compile on UBUNTU 18.04 OS successfully.

// C program to print all punctuation marks
// using ispunct() function

#include <stdio.h>
#include <ctype.h>

int main()
{
    int cnt;
    printf("Punctuation marks are: \n");

    for (cnt = 0; cnt <= 127; cnt++)
        if (ispunct(cnt) != 0)
            printf("%c ", cnt);

    printf("\n");

    return 0;
}

Output

Punctuation marks are: 
! " # $ % & ' ( ) * + , - . / : ; < = > ? @ [ \ ] ^ _ ` { | } ~

Explanation

Here, we printed all punctuation marks available in C language using the ispunct() library function on the console screen.

C Basic Programs »


Related Programs

Comments and Discussions!

Load comments ↻






Copyright © 2024 www.includehelp.com. All rights reserved.