need help with an ascii table =\

This is a discussion on need help with an ascii table =\ within the C++ Programming forums, part of the General Programming Boards category; How's it going everyone? I got a project due in a few days and I was trying to work this ...

  1. #1
    Registered User
    Join Date
    Apr 2002
    Posts
    3

    need help with an ascii table =\

    How's it going everyone? I got a project due in a few days and I was trying to work this but i can't figure out why its doing what it is. What i have to do i display the integer and its character values. this what i have in the driver:

    {
    while (RW<50)
    {
    cout << endl <<"Row:"<< RW;

    RW ++;

    while (CL<5)
    {
    cout << (char)AlphNum << "\t";

    AlphNum ++;
    CL ++;
    }

    CL=0;
    }
    }

    but this is how it displays:


    Row:0 ☺ ☻ ♥ ♦
    Row:1♣ ♠
    Row:2
    ♫ ♀
    Row:3☼ ► ◄ ↕ ‼
    Row:4¶ § ▬ ↨ ↑
    Row:5↓ → ← ∟ ↔

    the first if how its suppose to look then it goes downhill from there. row 1 and 2 are really messed up and the gap between the integer and the first char value in row 3, 4, & 5 are gone. i only showed you the first 6 but it looks like rows 3,4,&5 throughout the whole thing.

    any help guys?

  2. #2
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    Certain ASCII values represents Newline, Tab, Backspace and so on, that's probably the problem.
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  3. #3
    Registered User
    Join Date
    Apr 2002
    Posts
    3
    yeah i realize this, but how do i fix what i have above? i don't see the problem?

  4. #4
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,136
    Change what you initialized alphnum to.

  5. #5
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,802
    You shouldn't be trying to print out the non-printable characters. Isn't there an isprint function that let's you know if a value is printable or not? You could use this function to simply display some default character if it is not a printable character otherwise it is a printable character and you just output it.
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  6. #6
    Unregistered
    Guest
    (char)AlphaNum

    prints out the ASCII character that is number AlphaNum

    If AlphaNum == 0, then (char)AlphaNum == '\0'

    I believe '1' == (char)48 or somewhere close to that.

  7. #7
    Registered User
    Join Date
    Apr 2002
    Posts
    139
    The 0-31 & 127 are nonprintable control characters. Such as 8 which is backspace, 13 which is enter, 27 which is the esc key and 127 which is delete. You can print them but that funky stuff is what you get. Do as the other guy suggested and if it is one of those characters than skip it or change it to print off what the character does instead of printing the character.
    "The most common form of insanity is a combination of disordered passions and disordered intellect with gradations and variations almost infinite."

  8. #8
    Registered User Dual-Catfish's Avatar
    Join Date
    Sep 2001
    Posts
    802
    Actually I think the function is isgraph() in ctype.h..
    You can view what characters are what @ www.asciitable.com

  9. #9
    Registered User
    Join Date
    Apr 2002
    Posts
    3
    ok well i'm all new to this programming thing since this is my first class so i'm a dope.

    Code:
    #include <iostream.h>
    
    int RW=0, CL=0, AlphaNum=0;
    
    void main(void)
    {
    
         cout << "Columns  1   2   3   4   5" << endl;
    
         while (RW<255)
         {
            cout <<"Row #" << RW << ": ";
    
            RW ++;
    
            while (CL<5)
            {
              if (AlphaNum == 0 || AlphaNum == 7 || AlphaNum == 8 || AlphaNum == 9 || AlphaNum == 13)
                   cout << "(" << AlphaNum << ") ";
              else if (AlphaNum != 10)
                   cout << "("<< char(AlphaNum) << ") ";
              else
                   cout << "(\\n) ";
    
    	AlphaNum ++;
    	CL ++;
    	}
    		
    	cout << endl;
    		
    	CL=0;
         }
    
    }
    now it all prints good until row 53, 104, 105, 155, 156, 207, 208.
    now i've come to realize that its when it reaches the char value of 7 is when things start to go wacky. i also realize that when it gets to the higher rows AlphaNum is no longer 7 or 8 or 10 or etc.. like it was at the beginning. so i belive this is where the problem comes from. i just don't know how to fix it. can anyone help?

  10. #10
    Registered User
    Join Date
    Apr 2002
    Posts
    139

    the solution?

    After looking at your code again I think i found the problem,
    Code:
    while (RW<255)
         {
            cout <<"Row #" << RW << ": ";
    you are increasing the RW by 1 each time while AlphaNum is increasing by 5 thus causing the problem. instead use AlphaNum as the flag.
    Code:
    while (AlphaNum<255)
         {
            cout <<"Row #" << AlphaNum/5+1 << ": ";
    Hope that helps
    "The most common form of insanity is a combination of disordered passions and disordered intellect with gradations and variations almost infinite."

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Writing array, to file
    By zootreeves in forum C Programming
    Replies: 9
    Last Post: 09-08-2007, 05:06 PM
  2. ASCII Table
    By peckitt99 in forum C Programming
    Replies: 21
    Last Post: 10-09-2006, 01:53 AM
  3. help! extended ascii table
    By godhand in forum Linux Programming
    Replies: 7
    Last Post: 10-07-2003, 05:20 PM
  4. ASCII table going crazy?
    By Jamsan in forum Windows Programming
    Replies: 19
    Last Post: 03-27-2003, 01:33 AM
  5. Printing characters not in the ASCII table
    By Unregistered in forum C Programming
    Replies: 2
    Last Post: 01-21-2002, 12:47 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21