Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1014075
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T10:11:59+00:00 2026-05-16T10:11:59+00:00

got a question regarding printing out the 128 first characters from the ascii table.

  • 0

got a question regarding printing out the 128 first characters from the ascii table. I haven’t gotten so far yet, because I already stumbled to a problem. The following code prints the correct value starting from 32-127. From 0 to 31 however it prints out some scrap values. I assume it is correct as well since I quick checkup on the asciitable.com those values represents something else beside the ABC…Z.

So my question is how I can print out those values as in the example output? And also I want to know how one should write a program which print out like the example output. Since the solutions I can think off would give me output e.g. 1 to 10 chars in a rows instead for in columns.

int main()
{
    int i =0;
    for(int rows = 0; rows < 16; rows++)
    {
        i = rows;
        while(i <= 127)
        {
            if(i <= 15)
                cout << hex << setw(2) << setfill('0') << i << "= " << setw(2) << setfill(' ') << toStr(i) << " | ";
            else
                cout << hex << setw(2) << setfill('0') << i << "= " << setw(2) << setfill(' ') << char(i) << " | ";
            i+=16;
        }

        cout << "\n";
    }

    return 0;
}

Example output

+--------+--------+--------+--------+--------+--------+--------+--------+
| 00     | 10     | 20 ' ' | 30 '0' | 40 '@' | 50 'P' | 60 '`' | 70 'p' |
| 01     | 11     | 21 '!' | 31 '1' | 41 'A' | 51 'Q' | 61 'a' | 71 'q' |
| 02     | 12     | 22 '"' | 32 '2' | 42 'B' | 52 'R' | 62 'b' | 72 'r' |
| 03     | 13     | 23 '#' | 33 '3' | 43 'C' | 53 'S' | 63 'c' | 73 's' |
| 04     | 14     | 24 '$' | 34 '4' | 44 'D' | 54 'T' | 64 'd' | 74 't' |
| 05     | 15     | 25 '%' | 35 '5' | 45 'E' | 55 'U' | 65 'e' | 75 'u' |
| 06     | 16     | 26 '&' | 36 '6' | 46 'F' | 56 'V' | 66 'f' | 76 'v' |
| 07'\a' | 17     | 27 ''' | 37 '7' | 47 'G' | 57 'W' | 67 'g' | 77 'w' |
| 08'\b' | 18     | 28 '(' | 38 '8' | 48 'H' | 58 'X' | 68 'h' | 78 'x' |
| 09'\t' | 19     | 29 ')' | 39 '9' | 49 'I' | 59 'Y' | 69 'i' | 79 'y' |
| 0a'\n' | 1a     | 2a '*' | 3a ':' | 4a 'J' | 5a 'Z' | 6a 'j' | 7a 'z' |
| 0b'\v' | 1b     | 2b '+' | 3b ';' | 4b 'K' | 5b '[' | 6b 'k' | 7b '{' |
| 0c'\f' | 1c     | 2c ',' | 3c '<' | 4c 'L' | 5c'\\' | 6c 'l' | 7c '|' |
| 0d'\r' | 1d     | 2d '-' | 3d '=' | 4d 'M' | 5d ']' | 6d 'm' | 7d '}' |
| 0e     | 1e     | 2e '.' | 3e '>' | 4e 'N' | 5e '^' | 6e 'n' | 7e '~' |
| 0f     | 1f     | 2f '/' | 3f '?' | 4f 'O' | 5f '_' | 6f 'o' | 7f     |
+--------+--------+--------+--------+--------+--------+--------+--------+

EDIT
I got a quite ok solution now I think, edited the code. Beside understanding how to print in columns I also used the function which Martin nicely provided.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T10:11:59+00:00Added an answer on May 16, 2026 at 10:11 am

    If the character is smaller than 32 it is a special character and thus may not have a vueable glyph. So if the character is below 32 you should take this into account and put an appropriate character string in its place.

    #include <iostream>
    
    // An array of strings for all the special characters.
    char const* data[] = {"", "", "", "", "", "", "", ""
                          "\\a","\\b","\\t","\\n","\\v","\\f","\\r"
                          // etc
                         };
    
    char const* toStr(int loop)
    {
        // Used by normal character.
        // Note buffer[0] is where we put the char. buffer[1] is always '\0'
        static char buffer[] = " ";
    
        if (loop < 32)
        {
            return data[loop];
        }
        else
        {
            buffer[0] = loop;
            return buffer;
        }
    }
    
    int main()
    {
        for(int loop =0;loop < 128;++loop)
        {
            std::cout << loop << "=" << toStr(loop) << "\n";
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got a question regarding a SQL-select-query: The table contains several columns, one of
I got this question from this discussion . A method call like object.m does
So I got this question from one of the developers in my team: What
I got a question regarding content types and their IDs and how to use
I got a question regarding my MySQL-database and would like to get input on
I ve got a question regarding jBPM. In one of our projects I developed
I've got another question regarding to basic Android programming: How can I access the
I've got a question regarding the difference between PropertyPlaceholderConfigurer (org.springframework.beans.factory.config.PropertyPlaceholderConfigurer) and normal filters defined
I am (very) new to WPF and I have got a question regarding that.
I got a question regarding C++ Object & Javascript Object life cycle mis-synchronization and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.