Printing ASCII Table with Numbers and corresponding characters.

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");

}


Mistake made in this program was two variables one with int and one with char type were taken...the other being redundant.
The change has been made here on the blog, but it still remains to be changed in the file to be downloaded. Will do that soon.


The file can be downloaded at:
Download File

Comments

Anonymous said…
Gut, aber weisst Du dass 'charac' ueberflussig ist? Du koenntest einfach sowas tun:

printf("\nValue:%d = ASCII Character:%c", num, num);

Viel Erflog beim C lernen...
Copper Skull said…
Vielen Danke..

I will change it..I hurriedly made those programs...and put that stupid logic!

ich bedanke mich wieder...

Ich versteh nicht deutsch viel.
I am learning it though! Still an amateur..[:(]
Anonymous said…
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.
Copper Skull said…
Thats what was done previously..

I would like to translate the very First Comment (the one in German).

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..hehe
Thiago Farina said…
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;
}
Sushil said…
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();

}
raj said…
#include
#include
void main()
{
char c=0;
while(c<255)
printf("\n%d ascii value is %c",c,c);
c=c+1;
}
Anonymous said…
#include
int main()
{
int i;
for(i=1;i<=255;i++)
{
printf("value=%d & ASCII=%c \n",i,i);
}
}
Anonymous said…
#include
void main()
{
int i;
char j;
for (i=0,j=0;i<=255;j++,i++)
{
printf("character %c ,Value %d\n", j,i);
}
}

Popular posts from this blog

C Program - Calculation of Area and Circumference of a Circle using Pointers

Matchstick Game using C Programming

C Program to Calculate Factorial of a number using Recursion