Thread: Ascii values

  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 int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    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.

  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
    28,413
    Sounds plausible. There are only 128 characters in ASCII anyway.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  6. #6
    Registered User
    Join Date
    Mar 2011
    Posts
    278
    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, 01: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, 07:16 PM
  5. Testing for ASCII values?
    By csmatheng in forum C Programming
    Replies: 1
    Last Post: 02-19-2002, 02:22 PM