How to write a C Program to Printing ASCII Table with Numbers and corresponding characters in C Programming Language ?
The following program prints the ASCII Table with the numbers from 0 to 255 and their corresponding equivalent characters in ASCII.Write a program to print all the ASCII values and their equivalent characters using a while loop. The ASCII values vary from 0 to 255.
- #include<stdio.h>
- main()
- {
- int num;
- printf("Printing ASCII values Table...\n\n");
- num = 1;
- while(num<=255)
- {
- printf("\nValue:%d = ASCII Character:%c", num, num); /*This change has been made as per the comment. Thank you anonymous Blog Viewer ... */
- num++;
- }
- printf("\n\nEND\n");
- }
the program should have a char input declaration .. ie..
int num;
char c;
.
.
.
then, after the while loop
printf("\n Value:%d= ASCII character:%c",num,c);
.. because the character variable in the above printf statement cannnot be "num" as it has been declared as the integer variable at the start of the program.
It says that there's not need for the char variable. printf("%c", int_variable)..will always produce an output which is the ASCII equivalent of the then value of that int_variable.
So, introducing a new char variable would be absolutely unnecessary.
Always keep in mind..the programs that we make always have to be compact. The most compact and the most efficient program bags the prize
You could simplify and use a for loop instead.
- #include
- int main(void)
- {
- printf("Printing ASCII values Table...\n\n");
- for (int i = 1; i <= 255; ++i)
- {
- printf("\nValue:%d = ASCII Character:%c", i, i); /*This change has been made as per the comment. Thank you anonymous Blog Viewer ... */
- }
- printf("\n\nEND\n");
- return 0;
- }
We should define (char)c=num(int); such as in this code.
- #include
- #include
- main()
- {
- int num;
- char c;
- printf("Printing ASCII values Table...\n\n");
- num = 1;
- while(num<=255)
- {
- c=num;
- printf("\nValue:%d = ASCII Character:%c", num, c);
- num++;
- }
- printf("\n\nEND\n");
- getche();
- }
C Program to Printing ASCII Table with Numbers and corresponding characters
- #include
- void main()
- {
- int i;
- char j;
- for (i=0,j=0;i<=255;j++,i++)
- {
- printf("character %c ,Value %d\n", j,i);
- }
- }
Learn More :
Table
- C Program Array NxM Elements Geometric/Arithmetic
- C Program To Print Table Horizontally
- C Program To Generate Multiplication Table
- C program calculates a given function in range given by user, stores the data in arrays and displays the answer in a table.
- C Program to print table vertically
- C Program contains all the functions that interact directly with the routing table, as well as the main entry method for routing
- C Program Contains all the Functions that interact directly with routing table
print
- PRINT PRIME NUMBERS BETWEEN 1-300 USING BREAK AND CONTINUE IN C
- Write a c program to print Pascal triangle.
- C or C++ Program To Print Prime Number
- C Program print fill zero & mod/div
- C Program to printf & scanf Example
- C Program to Print a String Without Use Semicolon.
- C Program To Input & Print More Than One Words In Single Line
- C Program To Print Alphabets Like {Aa Bb Cc...}
- C Program To Print Alphabets Like {Az By Cx...}
- C Program To Print Lines Of A Paragraph Having More Than 15 Characters
- C Program To Print Prime Numbers Upto The Number You Want
- C Program To Print String In Formatted Output Form
- C Program To Print Sum Of n Digit Number
- C Program To Print Table Horizontally
- C Program To Print Tridiagonal Matrix
- C Program To Print Text Into Uppercase
- C Program to print all prime numbers from 1 to 300.
- C program that lets the user choose if he wants to add a item to the shopping list or print it out
- C Program to print table vertically
- Loudness Program: Gets loudness level from user; chooses a response And prints it using logical and operative statements
- C program that receives 10 float numbers from the console and sort them in non-ascending order, and prints the result
- Function should print the cartesian coordinates of the struct argument
- C Program Read a char & print next char ( file to file )
- Primul meu program in C Program
Characters
- C Program Character toupper() Example
- C Program Character Example
- C Program To Print Lines Of A Paragraph Having More Than 15 Characters
- C Program To Copy One Character Array Into Another
- C Program to Print ASCII equivalent of a character until terminated by key is ‘x’
- C Program to find the number of unique characters
- C Program to Compare Two Character
- Design a C function that shortens a string to 8 characters
- Menu driven program in C which performs the following operations on strings
- File Handling (console to file) in C Program
Number
- Find out the perfect number using c program
- Write a c program to find out H.C.F. of two numbers.
- Check the given number is armstrong number or not using c program.
- Write a c program to find largest among three numbers using conditional operator
- FIND OUT GENERIC ROOT OF A NUMBER - C PROGRAM.
- FIND PRIME FACTORS OF A NUMBER USING C PROGRAM
- How To Write a C program that generates two random numbers ?
- Write a C program to find maximum or equal between two numbers ?
- How to Write a C program to find maximum between two numbers ?
- Write a C program to perform math operations on two input whole numbers. The operations are:
- Write a C program to find maximum between three numbers ?
- Sort Three Numbers - program reads in three Integers and displays them in ascending order.
- C Program to Enter an ODD number between 1 and 49.
- C program acquires keyboard 10 numbers for each of these numbers to determine if it is a first issue, by printing immediately message should at the end, if none of the numbers you entered was a first issue, print an appropriate message.
- C program generates a random number and uses an algorithm to generate 9 other numbers.
- C Program to Find Random Number
- C Program To Find LCM and HCF Of Two Number Using Function - 2
- C Program to find LCM and HCF Of Two Number Using Recursion - 3
- C Program To Find LCM and HCF Of Two Number -1
- C Program To Find Reverse Of Any Digit Number
- C Program To Find The Frequency Of A Number
- C Program To Print Prime Numbers Upto The Number You Want
- C Program To Print Sum Of n Digit Number
- C Program To Reverse A Number
- C Program To Search A Number Inside The Array