Solution for Exercise 7-1

ex0701

#include <stdio.h>

int main()
{
    int c;

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

Output

I'm waiting for a character: C
I waited for the 'C' character.

Notes

*The output above assumes the user typed C as the character.

* The character read by getchar() is stored in the computer as an ASCII code value. Refer to Appendix A in the book for the list of ASCII codes and the characters they represent.