Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Printing ascii chart

Tags:

c++

c

ascii

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.

like image 834
Sandip Kumar Avatar asked Dec 12 '16 10:12

Sandip Kumar


People also ask

What does printable ASCII mean?

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.

How many ascii characters can be printable?

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.


2 Answers

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.

like image 69
artm Avatar answered Sep 20 '22 01:09

artm


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.

like image 25
Sourav Ghosh Avatar answered Sep 22 '22 01:09

Sourav Ghosh