ASCII Table

Jun 25, 2011 at 9:35pm
Hi guys,
I've created an ASCII table. Whenever I compile it, the system gives a beep sound but still the console shows the table. I know something is wrong with the coding. But I don't know what. What should I do to avoid this?
Here is the coding. Please help. Thanks in advance.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// ASCII Table
#include <iostream>
#include <iomanip>

using namespace std;

int main ()
{
   int ascii      (0);    // Ascii values' loop
   int asciiBreak (9);   //  To break ascii loop

   for (int col = 0; col <= 9; col++)
   {
      cout  << setw (7) << col;
   }

   cout  << endl;

   for (int row = 0; row <= 12; row++)
   {
      cout << row;
      for (; ascii <= 129; ascii++)
      {
         cout << setw (7) << static_cast<char>(ascii);
         if (ascii == asciiBreak)
            break;
      }
      cout << endl << endl;
      ascii +=1 ;
      asciiBreak = asciiBreak + 10;
   }
   return 0;
}

Jun 25, 2011 at 9:44pm
In ASCII, characters below 32 are control codes with no graphical representation. One of them (I can't remember which one) causes the terminal to beep.
Jun 25, 2011 at 9:46pm
It's 7, that's what's traditionally used to signal a beep. Some of the values below 32 do have some form of graphical representation in some cases, however.
Last edited on Jun 25, 2011 at 9:48pm
Jun 25, 2011 at 9:51pm
Hi helios,
Thanks indeed for your reply.
To be honest, I don't have prior programming experience. I'm learning C++ through online tutorial and some e-books. Would you please be quite explicit? Will this crash the system? I'm new so I want to know is that worrying if system beeps when compiling a coding?
Jun 25, 2011 at 9:56pm
It won't crash the system, but you can get strange behavior. For example 8 is backspace, 9 is tab, 13 is carriage return, 27 is escape.
Jun 25, 2011 at 9:57pm
Thank you very much, Ikaron.
Jun 25, 2011 at 10:25pm
Except that even though 8 is backspace, it doesn't backspace at all...
Jun 25, 2011 at 10:31pm
It does, actually. At least on some terminals. Although not up to the previous line.
Jun 25, 2011 at 10:31pm
Except that even though 8 is backspace, it doesn't backspace at all...

Bring up the command line, type a letter in, hold alt and push 8 on the number pad, let go of alt.

It does, actually. At least on some terminals.

It can actually work elsewhere too, like notepad, except there it's alt + 08. A bit inconsistant, isn't it? xD
Last edited on Jun 25, 2011 at 10:35pm
Jun 25, 2011 at 10:48pm
Typing a letter and hitting alt+num8 works fine, but what I meant was that you can't do this:
cout << 'h' << '\b';
For me, this prints h and does not backspace it.
Jun 25, 2011 at 10:52pm
Because if you cout << 'h'; cin >> x; and hit backspace, it won't erase the h, either. It literally is hitting backspace.
Jun 25, 2011 at 10:57pm
Remember that ASCII was originally used for sending data to line printers. "Backspace" means "move the carriage back one space". It doesn't have to delete the character. In fact, I wouldn't be surprised if some old terminals used the combination "a\b¨" to make ä.
Last edited on Jun 25, 2011 at 10:57pm
Jun 25, 2011 at 10:58pm
@Intrexa: Which is why I said it doesn't backspace anything if you print it out. We were talking about printing characters, and I said that it doesn't backspace anything. I think this was a simple misunderstanding.
Last edited on Jun 25, 2011 at 10:58pm
Jun 25, 2011 at 11:07pm
Oops, if only English was as verbose as programming languages.
Topic archived. No new replies allowed.