ASCII character with ASCII value 0 and 32

This is a discussion on ASCII character with ASCII value 0 and 32 within the C Programming forums, part of the General Programming Boards category; Hello friends, I am new to programming. I just wish to know what are the characters represented by ASCII values ...

  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
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,522
    > 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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,333
    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
    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
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,158
    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

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