putch(lastInit);
The next chapter explains more built-in functions, including two that quickly input and output strings
as easily as this chapter’s I/O functions work with characters.
The Absolute Minimum
This chapter’s goal was to explain a few additional input and output functions. The
functions presented here are character I/O functions. Unlike scanf() and
printf(), the getchar(), getch(), putchar(), and putch() functions
input and output single characters at a time. Key concepts from this chapter include:
- Use getchar() and putchar() to input and output single characters.
- Use a standalone getchar() to get rid of the Enter keypress if you don’t want to
capture it. You also can create a loop to call getchar() until the return value is
\n, as shown in the sample code. - Use getch() to get unbuffered single characters as soon as the user types them.
- Don’t use a character I/O function with character variables. Use an int variable
instead. - Don’t forget to print character input using putch() if you want that input echoed
on the screen as the user types.