Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

Printing ASCII Code

printing ascii

  • Please log in to reply
9 replies to this topic

#1 Egz0N

Egz0N

    CC Leader

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1155 posts

Posted 26 November 2009 - 02:58 AM

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)

int i;
char a;


then we use this loop:

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 ..

a=i;

now, using "iomanip" we format the output .. the iomanip code will look like as following:

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:

#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:

http://forum.codecal...=1&d=1259233059 ..


Thanks,

Egz0N ..

Attached Thumbnails

  • ASCII.JPG

Attached Files


Edited by Egz0N, 28 November 2009 - 03:07 AM.

  • 8

#2 WingedPanther73

WingedPanther73

    A spammer's worst nightmare

  • Moderator
  • 17757 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others

Posted 27 November 2009 - 06:42 AM

Nice and simple, I like it. +rep
  • 0

Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

My MineCraft server site: http://banishedwings.enjin.com/


#3 Guest

Guest

    CC Devotee

  • Expert Member
  • PipPipPipPipPipPip
  • 914 posts
  • Programming Language:C

Posted 27 November 2009 - 01:26 PM

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

#4 Egz0N

Egz0N

    CC Leader

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1155 posts

Posted 27 November 2009 - 02:39 PM

Nice and simple, I like it. +rep


thanks WP ..

Nice way to generate a quick ASCII table.
Posted Image


thanks mate :)
  • 0

#5 chili5

chili5

    CC Mentor

  • Expert Member
  • PipPipPipPipPipPipPipPip
  • 3038 posts
  • Programming Language:Java, C#, PHP, JavaScript, Ruby, Transact-SQL
  • Learning:C, Java, C++, C#, PHP, JavaScript, Ruby, Transact-SQL, Assembly, Scheme, Haskell, Others

Posted 27 November 2009 - 05:43 PM

Interesting, but, what are ASCII values?
  • 0

#6 Egz0N

Egz0N

    CC Leader

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1155 posts

Posted 28 November 2009 - 12:16 AM

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.
  • 0

#7 Guest_Jordan_*

Guest_Jordan_*
  • Guest

Posted 28 November 2009 - 06:56 AM

Nicely written! Simple and easy to follow. +rep
  • 0

#8 Egz0N

Egz0N

    CC Leader

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1155 posts

Posted 28 November 2009 - 09:12 AM

thanks .. :)
  • 0

#9 ZekeDragon

ZekeDragon

    CC Leader

  • Retired Mod
  • PipPipPipPipPipPipPip
  • 1263 posts

Posted 01 December 2009 - 09:00 AM

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.
a = (char) i;
Not necessary, maybe, but clearer. :)

Anyway, great little tutorial! Plus rep
  • 0
If you enjoy reading this discussion and are thinking about commenting, why not click here to register and start participating in under a minute?

#10 Egz0N

Egz0N

    CC Leader

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1155 posts

Posted 01 December 2009 - 09:03 AM

ahh .. thanks .. :)
  • 0





Also tagged with one or more of these keywords: printing, ascii

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download