Q:

C program to print all punctuation marks without using library function

0

C program to print all punctuation marks without using library function

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Here, we will print all punctuation marks are available in C language without using any library function.

Program:

The source code to print all punctuation marks without using the library 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
// without using library function

#include <stdio.h>

int isPunctuation(char ch)
{
    if (ch == '!' || ch == '"' || ch == '#' || ch == '$' || ch == '%' || ch == '&' || ch == '\'' || ch == '(' || ch == ')' || ch == '*' || ch == '+' || ch == ',' || ch == '-' || ch == '.' || ch == '/' || ch == ':' || ch == ';' || ch == '<' || ch == '=' || ch == '>' || ch == '?' || ch == '@' || ch == '[' || ch == '\\' || ch == ']' || ch == '^' || ch == '`' || ch == '{' || ch == '|' || ch == '}' || ch == '~')
        return 1;

    return 0;
}

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

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

    printf("\n");

    return 0;
}

Output:

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

Explanation:

Here, we created two functions isPunctuation() and main(). The isPunctuation() function is used to check the given character is a punctuation mark or not.

In the main() function, we printed all punctuation marks available in C language without using the library function.

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

C programming Basic Input, Output, if else, Ternary Operator based Programs

Similar questions


need a help?


find thousands of online teachers now
C program to print all punctuation marks using the... >>
<< C program to convert an uppercase character into l...