I was trying to print complete ASCII chart . Meanwhile I saw this code on tutorialsschool.com website .
#include<stdio.h>
void main() {
int i;
for(i=0;i<=255;i++){
printf("%d->%c\n",i,i);
}
}
It looks perfect, but the problem is that it is not printing symbols for locations (I'm using Code::Blocks IDE) such as 7,8,9,10 and 32. I am really confused why it not printing values at those locations.And it is giving some weird output on online compilers.Is it the problem of Code::Blocks. What possibly could be the other program to print these ASCII symbols.
ASCII printable characters (character code 32-127) Codes 32-127 are common for all the different variations of the ASCII table, they are called printable characters, represent letters, digits, punctuation marks, and a few miscellaneous symbols. You will find almost every character on your keyboard.
There are 95 printable ASCII characters, numbered 32 to 126. ASCII (American Standard Code for Information Interchange), generally pronounced [ˈæski], is a character encoding based on the English alphabet. ASCII codes represent text in computers, communications equipment, and other devices that work with text.
I am really confused why it not printing values at those locations.
Because those code is non-printable ASCII code. Note standard ASCII code has only 7 bit (ie 128 characters) - and several of them non-printable (control codes) - so you are not expected to be able print them (eg, can you print the Bell 0x07 ?)
http://www.asciitable.com/
And as Mohit Jain pointed out, you really need to use isprint
function to check if a character is printable on standard C locale before printing it out - very handy function.
You might be interested in knowing that not all the ASCII characters are printable.
For example, decimal 0 to 31 are non-printable ASCII values.
See this reference, which mentions the same.
That said, for a hosted environment, the expected signature of main()
is int main(void)
, at least.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With