Q:

C program to print all printable characters without using the library function

0

C program to print all printable characters without using the 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 printable characters are available in C without using the library function.

Program:

The source code to print all printable characters 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 printable characters
// without using library function

#include <stdio.h>
#include <ctype.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 isAlphaNumeric(char ch)
{
    if ((ch >= '0' & ch <= '9') || (ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z'))
        return 1;

    return 0;
}

int isPrintable(char ch)
{
    if (isAlphaNumeric(ch) || isPunctuation(ch))
        return 1;
    return 0;
}

int main()
{
    int cnt;
    printf("Printable characters are: \n");

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

    printf("\n");

    return 0;
}

Output:

Printable characters are: 
! " # $ % & ' ( ) * + , - . / 
0 1 2 3 4 5 6 7 8 9 : ; < = > ? @ 
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 
[ \ ] ^ ` a b c d e f g h i j k l m n o p q r s t u 
v w x y z { | } ~

Explanation:

Here, we created four functions isPunctuation()isAlphanumeric()isPrintable() and main(). The isPrintable() function is used to check the given character is printable or not.

In the main() function, we printed all printable characters 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 make a beep sound... >>
<< C program to print all printable characters using ...