Thread: ASCII character with ASCII value 0 and 32

  1. #1
    Registered User
    Join Date
    Jul 2007
    Posts
    10

    ASCII character with ASCII value 0 and 32

    Hello friends,

    I am new to programming. I just wish to know what are the characters represented by ASCII values 0 and 32.

    In ASCII list which I dowloaded from internet it is written that ASCII character represented by value 0 is null character.

    But when I checked it by printing the character ( making a C program), it seems to be space. But character represented by value 32 also seems to be space character.

    Please clear my doubt.

    Thanks a lot.
    bye n take care.

  2. #2
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,613
    > it seems to be space

    I wouldn't rely on that. The reason ascii works to some extent is because the entire set can be represented by a byte, and zero bytes is meaningless in that context. Trying to print null and getting a space is purely a coincidence or an implementation detail. You could "print" zero bytes and put whatever on the screen really, like one of those box characters. Trying to print null bytes in shell programs usually wind up doing nothing but adding zero bytes to some sort of stream, and that don't show up at all in the programs that you use day to day.

  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
    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
    Linux is where it's at movl0x1's Avatar
    Join Date
    May 2007
    Posts
    72
    Print out an ascii table with this code and it'll show all the ascii characters and their
    values on stdout

    Code:
    #include <stdio.h>
    #include <ctype.h>
    
    int main(void)
    {
         unsigned int i;
        
         /* print an ascii table */
         for (i = 0; i < 256; i++) {
               if (isascii(i))
                   printf("&#37;d =%c, ", i, i);
               else
                   printf("%d =., ", i);
    
                /* print 10 values on each line */
                if ((i % 10) == 0)
                   printf("\n");
         }
    
         return 0;
    }
    Last edited by movl0x1; 07-24-2007 at 04:26 AM.
    Remember that all that code you write turns into this:

    0100100100110010010011100100111001001
    0010100100100001001111100010010010010 ....

  5. #5
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by hitesh_best View Post
    But when I checked it by printing the character ( making a C program), it seems to be space. But character represented by value 32 also seems to be space character.
    It isn't a space -- it is just "nothingness." This happens to LOOK like a space.

Popular pages Recent additions subscribe to a feed