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
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
printf("\nValue:%d = ASCII Character:%c", num, num);
Viel Erflog beim C lernen...
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..[:(]
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.
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
#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;
}
#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();
}
#include
void main()
{
char c=0;
while(c<255)
printf("\n%d ascii value is %c",c,c);
c=c+1;
}
int main()
{
int i;
for(i=1;i<=255;i++)
{
printf("value=%d & ASCII=%c \n",i,i);
}
}
void main()
{
int i;
char j;
for (i=0,j=0;i<=255;j++,i++)
{
printf("character %c ,Value %d\n", j,i);
}
}