ASCII Table

This is a discussion on ASCII Table within the C Programming forums, part of the General Programming Boards category; i am trying to write a program that will output an ascii table. the only way i can think of ...

  1. #1
    Is Trying to Learn
    Join Date
    Mar 2006
    Location
    Hutton, Preston
    Posts
    215

    ASCII Table

    i am trying to write a program that will output an ascii table. the only way i can think of doing this is to write them all out line by line, but i have heard that you can do this in a loop. i am unsure how to do this in a loop.

    can anyone help?

  2. #2
    Register User andor's Avatar
    Join Date
    Aug 2006
    Location
    Novi Sad
    Posts
    42
    There are 255 of them plus NULL. So from 0 to 256. You can printf like printf("%c %d 0x%x\n", i, i, i); in aloop afcourse.
    Last edited by andor; 10-06-2006 at 08:08 AM.

  3. #3
    csd@auth
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    71

    is this what you want?

    #include<stdio.h>

    int main()
    {
    char ch=0;
    int i;

    for(i=0;i<=122;i++)
    {
    printf("%c \n",ch);
    ch++;
    }

    getchar();
    return 0;
    }

  4. #4
    Registered User SKeane's Avatar
    Join Date
    Sep 2006
    Location
    England
    Posts
    234
    Bear in mind that several of the ASCII characters are non-printable and will have "unexpected" effects if you attempt to print them. You might want to look at isprint() in ctype.h

  5. #5
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,669
    Better than what most people could hardcode:
    http://www.lookuptables.com/

  6. #6
    Is Trying to Learn
    Join Date
    Mar 2006
    Location
    Hutton, Preston
    Posts
    215
    the code above is what i need but i put it in (prob not what i was ment to but i have not used C before) and it didnt do anything. is there anything im doing wrong?

  7. #7
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,669
    It really doesn't get any easier than:
    Code:
    #include <stdio.h>
    
    int main ( void )
    {
       unsigned int ch;
       for ( ch = 0; ch < 0xFF; ch++ ) {
          printf("%3d 0x%X %c ", ch, ch, ch);
          if ( !(ch % 4 ) )
             putchar('\n');
       }
       return 0;
    }
    While Skeane is correct in his post, very little of the ASCII table is printable, but they do hold some value. If you want to see how your terminal renders that value, some risk is involved.
    Last edited by whiteflags; 10-07-2006 at 01:38 PM.

  8. #8
    Is Trying to Learn
    Join Date
    Mar 2006
    Location
    Hutton, Preston
    Posts
    215
    cool, thanx

  9. #9
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    Like screwing up display completely because you just accidently replaced the console character set. Happens easily on Linux if you 'cat' a binary file.

    Someone kind-of mentioned it, but here's it explicitely: ASCII has only 127 characters, from 0x00 to 0x7F. All higher values are extensions, like Windows-1252 (Win9x standard), ISO-8859-1 (Linux standard) or IBM/OEM-850 (DOS and Windows console standard on German systems).
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  10. #10
    Is Trying to Learn
    Join Date
    Mar 2006
    Location
    Hutton, Preston
    Posts
    215
    just one more question, how do u create a table to put them in?

  11. #11
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    "Now, just a simple question, how do I make the graphics for my game?"

    This isn't a simple question. You'd need to make a GUI application for that.
    "The Internet treats censorship as damage and routes around it." - John Gilmore

  12. #12
    Is Trying to Learn
    Join Date
    Mar 2006
    Location
    Hutton, Preston
    Posts
    215
    ok not a table like that just headings so you can see what each characture represents if you know what i i mean eg...

    0 1 2 4
    0

    1

    2

    3

    etc...

  13. #13
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Why do you need a lookup table at all? I fail to see the point of lookup tables for characters in this case.


    Quzah.
    Hope is the first step on the road to disappointment.

  14. #14
    Is Trying to Learn
    Join Date
    Mar 2006
    Location
    Hutton, Preston
    Posts
    215
    im not sure its just what the tutor wants and it is for uni so best do it. i know i need to use gotoxy i think unless there is an easier way. i just dont know how to implement it into ma code.

  15. #15
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    So you're just trying to print a grid? Print across until you're bored, then print a newline. Repeat until done.


    Quzah.
    Hope is the first step on the road to disappointment.

Page 1 of 2 12 LastLast
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. Replies: 11
    Last Post: 03-24-2006, 10:26 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