One More Example

Let's run one more printing example, one that makes use of some of C's special escape characters. In particular, the program in Listing 3.9 shows how backspace (\b), tab (\t), and carriage return (\r) work. These concepts date from when computers used teletype machines for output and they don't always translate successfully to contemporary graphical interfaces. For example, this listing doesn't work as described on some Macintosh implementations.

Listing 3.9 The escape.c program.
 /* escape.c--uses escape characters */ #include <stdio.h> int main(void) { float salary; printf("Enter your desired monthly salary:"); /* 1 */ printf(" $_______\b\b\b\b\b\b\b"); /* 2 */ scanf("%f", &salary); printf("\n\t$%.2f a month is $%.2f a year.", ...

Get C Primer Plus®, Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.