Thread: ASCII table going crazy?

  1. #1
    Registered User
    Join Date
    Feb 2003
    Posts
    162

    ASCII table going crazy?

    Well, I'm trying to output the ascii table, and most of it is fine....it'll print up to 127 Fine, but then it goes awire after that....anyone know why?

    Code:
    case 256:	{
    				RECT a;
    				int x = (ww - 220) / 2;
    				int y = 20;
    				a.left = x;
    				a.top = y;
    				a.right = x + 50;
    				a.bottom = y + 15;
    
    				pDC->DrawText("Index",&a,DT_SINGLELINE|DT_CENTER);
    
    				a.left = x+65;
    				a.right=x+135;
    				pDC->DrawText("Character",&a,DT_SINGLELINE|DT_CENTER);
    
    				a.left = x+150;
    				a.right = x+220;
    				pDC->DrawText("Frequency",&a,DT_SINGLELINE|DT_CENTER);
    
    				y+=20;
    
    				for (int i = 0; i < 256; i++)
    				{
    					sprintf(b, "%d", i);
    					pDC -> TextOut (x + 25, y, b);
    					sprintf(b, "%c", i);
    					pDC -> TextOut (x + 100, y, b);
    
    					sprintf(b, "%d", m_FreqAscii[i]);
    					pDC -> TextOut (x + 180, y, b);
    					y+=20;
    				}
    				break;
    			}

  2. #2
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,829
    First thought...

    127 = 0x7f
    128 = 0x80

    Not using a signed byte when you should be using an unsigned are you?

    What is b?
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  3. #3
    Registered User
    Join Date
    Feb 2003
    Posts
    162
    nope its an unsigned integer....b is just a temporary string

  4. #4
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,829
    >>> b is just a temporary string

    Declared where and how? It is very difficult to debug parts of program, very much easier to compile it and run it in a decent debugger. Can you not set a break point in the loop and watch what all the various values are doing when i goes from 127 to 128?

    To make sure it is the 127 -> 128 that is causing the problem, start your loop at, say, 10, rather than 0 and see if it still breaks at 127, or now at 137 or something.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  5. #5
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    That will just print what ever glyph is in the DC's current Font for that ascii code/index.
    You can use the "character map" utility that comes installed on most windows machines to see what glyph will be used for that font.

    Here's more info.

    gg

  6. #6
    Registered User
    Join Date
    Feb 2003
    Posts
    162
    right above the switch statement
    Code:
    char b[400];
    i didn't try your idea, but i did, if i was equal to 127, to not output that, and then dkeep going, but it still did the same thing....trying your idea now.

  7. #7
    Registered User
    Join Date
    Feb 2003
    Posts
    162
    Originally posted by Codeplug
    That will just print what ever glyph is in the DC's current Font for that ascii code/index.
    You can use the "character map" utility that comes installed on most windows machines to see what glyph will be used for that font.

    Here's more info.

    gg
    I have that table in front of me as well, here, let me show you an executable of the code ....(ill upload a text file incase you dont have any handy)...gimme a second

  8. #8
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,829
    >>> That will just print what ever glyph is in the DC's current Font for that ascii code/index.

    Yeah, but pretty much every font has at least some printable characters above 127. I suppose it is worth checking though.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  9. #9
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    F the table, read the text:
    The ASCII character code charts contain the decimal and hexadecimal values of the extended ASCII (American Standards Committee for Information Interchange) character set. The extended character set includes the ASCII character set and 128 other characters for graphics and line drawing, often called the "IBM character set."

    The characters that appear in Windows above 127 depend on the selected typeface.
    That will just print what ever glyph is in the DC's current Font for that ascii code/index [especially for characters above 127].
    All I was pointing out.

    gg

  10. #10
    Registered User
    Join Date
    Feb 2003
    Posts
    162
    ok well here is the executable, and here is a test text file

  11. #11
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,829
    You'll find that people will not in general download and run unknown executables from whatever source, there is just too much malicious stuff around.

    If you want someone to try it, post the source plus any special headers and resource files necessary, and they can compile it themseleves, (zip it together and post the .zip).
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  12. #12
    Registered User
    Join Date
    Feb 2003
    Posts
    162
    ok, here is the source code...its in MFC, so i didnt think many people would have VC++...

  13. #13
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,829
    >>> so i didnt think many people would have VC++...

    Lot of pro's in here

    Okay, it compiles and runs fine. If I choose File Analysis->Fine Characteristics->Frequency of... I get a 0-255 list with an ASCII equivalent and the frequency of each in a file, (readme.txt).

    Some of the characters are printable in my default font, others print a splat. No suprise there.

    What command sequence should I issue to break it?
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  14. #14
    Registered User
    Join Date
    Feb 2003
    Posts
    162
    i'm really not sure what your asking?

    however, did u notice after 127 how things start to get crazy?

  15. #15
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    Put this in your OnDraw()...
    Code:
        LOGFONT lf = {0};
        strcpy(lf.lfFaceName,"Times New Roman");
        CFont font;
        font.CreateFontIndirect(&lf);
        pDC->SelectObject(font);
    Times New Roman will has more glyphs that will show up in the chart

    gg

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. Replies: 11
    Last Post: 03-24-2006, 11:26 AM
  4. help! extended ascii table
    By godhand in forum Linux Programming
    Replies: 7
    Last Post: 10-07-2003, 05:20 PM
  5. Printing characters not in the ASCII table
    By Unregistered in forum C Programming
    Replies: 2
    Last Post: 01-21-2002, 01:47 PM