+ Reply to Thread
Results 1 to 10 of 10

Thread: Printing ASCII Code

  1. #1
    Join Date
    Sep 2008
    Location
    Kosovo
    Posts
    4,032
    Rep Power
    44

    Printing ASCII Code

    Hello CodeCall Members,

    Today I'd like to Show you How to Make a Simple Program that Will Print us the ASCII Code .. using C++ ..

    Ok..! ,

    First of all we declare 2 variables .. ('i' as an integer and 'a' as a character)

    Code:
    int i;
    char a;
    then we use this loop:

    Code:
    for (i=30;i<=255;i++)
    the "i" starts from 30 because the other characters before 30 are some special characters (like ENTER etc..) .. so we say that from i=30 till i<=255 increasing the 'i' for 1 ..


    the 'a' character becomes the character with the ASCII code 'i' .. using this command ..

    Code:
    a=i;
    now, using "iomanip" we format the output .. the iomanip code will look like as following:

    Code:
            cout << setw(2)
                 << a
                 << setw(6)
                 << i;

    .. the "setw(2) will reserve 2 spaces for the character 'a' .. and setw(6) will reserve 6 spaces for the number 'i' ..


    finally the code will look like the following:

    Code:
    #include <iostream>
    #include <iomanip>
    using namespace std;
    
    int main()
    {
        int i;
        char a;
        
        for (i=30;i<=255;i++)
        {
            a=i;
            cout << setw(2)
                 << a
                 << setw(6)
                 << i;
        }
        cout << endl;
        
        return 0;
    }

    .. and the console application will look like the following:

    ..


    Thanks,

    Egz0N ..
    Attached Thumbnails Attached Thumbnails Printing ASCII Code-ascii.jpg  
    Attached Files Attached Files
    Last edited by Egz0N; 11-28-2009 at 03:07 AM.

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Location
    Advertising world
    Posts
    Many

     
  3. #2
    Join Date
    Jul 2006
    Posts
    16,491
    Blog Entries
    75
    Rep Power
    143

    Re: Printing ASCII Code

    Nice and simple, I like it. +rep
    Programming is a branch of mathematics.
    My CodeCall Blog | My Personal Blog

  4. #3
    Join Date
    Sep 2009
    Location
    USA
    Posts
    3,400
    Blog Entries
    5
    Rep Power
    37

    Re: Printing ASCII Code

    Nice way to generate a quick ASCII table.
    Root Beer == System Administrator's Beer
    Download the new operating system programming kit! (some assembly required)

  5. #4
    Join Date
    Sep 2008
    Location
    Kosovo
    Posts
    4,032
    Rep Power
    44

    Re: Printing ASCII Code

    Quote Originally Posted by WingedPanther View Post
    Nice and simple, I like it. +rep
    thanks WP ..

    Quote Originally Posted by Guest View Post
    Nice way to generate a quick ASCII table.
    thanks mate

  6. #5
    Join Date
    Mar 2008
    Posts
    7,145
    Rep Power
    86

    Re: Printing ASCII Code

    Interesting, but, what are ASCII values?

  7. #6
    Join Date
    Sep 2008
    Location
    Kosovo
    Posts
    4,032
    Rep Power
    44

    Re: Printing ASCII Code

    Quote Originally Posted by chili5 View Post
    Interesting, but, what are ASCII values?
    The American Standard Code for Information Interchange (acronym: ASCII) is a character-encoding scheme based on the ordering of the English alphabet. ASCII codes represent text in computers, communications equipment, and other devices that use text. Most modern character-encoding schemes, which support many more characters than did the original, are based on ASCII.

  8. #7
    Jordan Guest

    Re: Printing ASCII Code

    Nicely written! Simple and easy to follow. +rep

  9. #8
    Join Date
    Sep 2008
    Location
    Kosovo
    Posts
    4,032
    Rep Power
    44

  10. #9
    Join Date
    Jul 2009
    Location
    Santa Clarita, CA
    Posts
    2,111
    Blog Entries
    47
    Rep Power
    31

    Re: Printing ASCII Code

    A lot of C++ coders don't even know iomanip exists. Your tutorial appeases me, but it would be clearer if you cast i to a char first.
    Code:
    a = (char) i;
    Not necessary, maybe, but clearer.

    Anyway, great little tutorial! Plus rep
    Wow I changed my sig!

  11. #10
    Join Date
    Sep 2008
    Location
    Kosovo
    Posts
    4,032
    Rep Power
    44

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 1
    Last Post: 09-28-2010, 01:15 PM
  2. ASCII Code Help
    By iNEXSERTiON in forum C and C++
    Replies: 7
    Last Post: 01-14-2010, 04:51 PM
  3. ASCII Tic - Tac - Toe
    By Donovan in forum Games
    Replies: 5
    Last Post: 09-18-2009, 04:11 PM
  4. I need your help! Ascii Bin
    By Jordan in forum Member Software/Projects
    Replies: 97
    Last Post: 07-21-2009, 08:15 AM
  5. 3D ASCII Art Game
    By Muted in forum The Lounge
    Replies: 3
    Last Post: 04-24-2009, 10:07 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts