Jul 1, 2010

Extended ASCII Character Set


The following is a simple program which prints the characters of an extended ASCII character set

#include <stdio.h>

void printChar(unsigned char c, unsigned char d)
{
    printf("[ %3d ] = %c \t", c, d);
    if(c % 5 == 0) printf("\n");
}

int main()
{
    /* print Extended ASCII char set */
    int c = 0;
    unsigned char space = ' ';

    printf("ASCII CHARACTERS\n");
    for (c = 0; c < 256; ++c)
    {
        switch(c)
        {
            case  8: /* backspace       */
            case  9: /* horizontal tab  */
            case 10: /* new line        */
            case 11: /* vertical tab    */
            case 12: /* new page        */
            case 13: /* carriage return */
                printChar(c, space);
                break;
            default:
                printChar(c, c);
                break;
        }
    }
    printf("\n");
}

Q. Trace the output if int c is replaced with unsigned char in the above program ?

No comments :

Post a Comment