Thread: outputting a ASCII chart

  1. #1
    Unregistered
    Guest

    outputting a ASCII chart

    hi, I want to know how to output an ASCII chart. I know how to output a chart like this:

    1 2 3 4 5 6 7 8 9 10...

    but how do I output a chart like this?:

    1 6 11
    2 7 12
    3 8 13
    4 9 14
    5 10 15...

    any suggestions? I know there are 256 ASCII characters and I don't want to use a matrix or arrays for this (just need to output the chart to save memory). thanks for any help.

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    Code:
    #include <iostream>
    using namespace std;
    
    int main ( void )
    {
      unsigned char ch;
      for ( int i = 0; i < 16; i++ ) {
        ch = i;
        for ( int j = 0; j < 16; j++ ) {
          cout<< ch <<"  "<<flush;
          ch += 16;
        }
        cout<<endl;
      }
      return EXIT_SUCCESS;
    }
    -Prelude
    My best code is written with the delete key.

  3. #3
    Unregistered
    Guest
    Try to write out in your native language exactly what you would do if you were the computer. Then try to write the code.

    there are 256 symbols with ASCII values from 0-255. That could correspond to 16 by 16 chart. the program will manipulate ints but display characters via the technique called casting. If you think of the table as grid with each element of the grid having an x and a y coordinate (x, y) and each element of the grid having a single value associated with it (result); then:

    (0, 0) would be 0,
    (0, 1) would be 16;
    (0, 2) would be 32;
    (0, 3) would be 48 ;
    (1, 0) would be 1,
    (2, 0) would be 2
    etc.

    With a little thought (that's all I'm capable of at the moment) this corresponds to a general equation of result = x + y*16.

    Now try to change that set of english instructions (or whatever you come up with) into code:

    int x;
    int y;
    int result;

    for(x = 0; x < 16; x++)
    {
    for(y = 0; y < 16; y++)
    {
    result = x + (y * 16);
    cout << (char)result << ' ';//or whatever casting method you use
    }
    cout << endl;
    }

    now put that into a program, compile, and evaluate. If lucky, you have desired effect. If not....well, you should be able to take it from here.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. ASCII chart
    By arul in forum C Programming
    Replies: 2
    Last Post: 07-29-2008, 08:02 AM
  2. Replies: 11
    Last Post: 03-24-2006, 11:26 AM
  3. Outputting in a Chart Format
    By glider_pilot123 in forum C Programming
    Replies: 9
    Last Post: 10-14-2004, 06:11 PM
  4. Outputting ASCII characters?
    By Jamsan in forum C++ Programming
    Replies: 3
    Last Post: 03-24-2003, 07:14 PM
  5. Outputting as binary, not ASCII
    By Crossbow in forum C++ Programming
    Replies: 5
    Last Post: 04-29-2002, 09:47 PM