Ascii values

This is a discussion on Ascii values within the C Programming forums, part of the General Programming Boards category; hi all! m trying to print all the ascii values form 0 to 255. but certain values like value of ...

  1. #1
    Registered User
    Join Date
    May 2011
    Posts
    2

    Smile Ascii values

    hi all!
    m trying to print all the ascii values form 0 to 255. but certain values like value of 11,12,13 is not seen in the output. what colud be the reason . following is my code :
    Code:
    #include<stdio.h>
    #include<conio.h>
    main()
    {
    int iNum;
    clrscr();
    printf("ASCII CHART-->");
       for(iNum=0;iNum<=255;iNum++)
       printf("%d=%c\t",iNum.iNum);
    getch();
    return 0;
    }

  2. #2
    Registered User
    Join Date
    Sep 2008
    Posts
    200
    Quote Originally Posted by caliber005 View Post
    hi all!
    certain values like value of 11,12,13 is not seen in the output. what colud be the reason .
    Some characters have no printable representation. Try using isprint() from ctype.h, which returns true for any printable character, including space:

    Code:
    #include<stdio.h>
    #include<conio.h>
    
    #include <ctype.h>
    
    main()
    {
    int iNum;
    clrscr();
    printf("ASCII CHART-->");
        for(iNum=0;iNum<=255;iNum++)
            if (isprint(iNum))
                printf("%d=%c\t",iNum.iNum);
            else
                printf("%d (unprintable)\t");
    getch();
    return 0;
    }

  3. #3
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,551
    Ascii Table - ASCII character codes and html, octal, hex and decimal chart conversion
    Anything less than 32 is reserved for various control characters, such as newline and carriage return.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  4. #4
    Registered User
    Join Date
    May 2011
    Posts
    2
    Quote Originally Posted by JohnGraham View Post
    Some characters have no printable representation. Try using isprint() from ctype.h, which returns true for any printable character, including space:

    Code:
    #include<stdio.h>
    #include<conio.h>
    
    #include <ctype.h>
    
    main()
    {
    int iNum;
    clrscr();
    printf("ASCII CHART-->");
        for(iNum=0;iNum<=255;iNum++)
            if (isprint(iNum))
                printf("%d=%c\t",iNum.iNum);
            else
                printf("%d (unprintable)\t");
    getch();
    return 0;
    }
    Thanks for the above code.but now values only upto 126 are being displayed, rest is shown as unprintable

  5. #5
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,744
    Sounds plausible. There are only 128 characters in ASCII anyway.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  6. #6
    Registered User
    Join Date
    Mar 2011
    Posts
    261
    It would help if you'd look up ASCII. From wikipedia:

    "ASCII includes definitions for 128 characters: 33 are non-printing control characters ..."
    All your questions so far answered in part of one sentence.

    Now, there are some extensions to ASCII that put some additional things in the range 128-255, but I don't think it's pure ASCII.

  7. #7
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by mike65535 View Post
    Now, there are some extensions to ASCII that put some additional things in the range 128-255, but I don't think it's pure ASCII.
    Those extensions are highly regionalized (i.e. different for France than Germany than USA than Canada). Thus the bad old days of DOS code pages and windows Locations... The extension is commonly referred to as the ANSI character code.

    If he wants to see them he'll need to find his compiler's switch for "Char type is unsigned" and recompile...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. ASCII values help
    By Grant_Searle in forum C Programming
    Replies: 5
    Last Post: 10-22-2010, 09:01 AM
  2. Using ASCII Values
    By ga836044 in forum C Programming
    Replies: 7
    Last Post: 03-17-2004, 12:31 AM
  3. ascii values for keys
    By acid45 in forum C Programming
    Replies: 2
    Last Post: 05-12-2003, 07:13 AM
  4. adding ASCII values
    By watshamacalit in forum C Programming
    Replies: 1
    Last Post: 12-26-2002, 06:16 PM
  5. Testing for ASCII values?
    By csmatheng in forum C Programming
    Replies: 1
    Last Post: 02-19-2002, 01:22 PM

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