Solution for Exercise 7-2

ex0702

#include <stdio.h>

int main()
{
    int c;

    printf("I'm waiting for a character: ");
    c = getchar();
    printf("I waited for the '%d' character.\n",c);
    return(0);
}

Output

I'm waiting for a character: s
I waited for the '115' character.

Notes

* The ASCII code for little S (shown in the output above) is 115.

* To explore the ASCII code/character concept further, change Line 9 in the code (the second printf() statement) so that both the code value and character for variable c are displayed. Something like:

Click here to view my solution to the above problem.