PS I synthesize here in my own words what K&R teach, re-write all their example programs, character by character, solve all the C exercises they hand out. I comment to what K&R teach cursively. I do not copy-paste anything from the book! In regards to the percentages listed: books often have prefaces with Roman numbers and often also lengthy Appendices. In my calculation I include all pages that I effectively study and synthesize.
TCPL 2Ed - Page 010 to 011 - 5.66% CompletionThis
printf("%d\t%d\n", fahr, Celsius);
is the prntf function.
Printf is a general-purpose output formatting function. In its first argument is a string of characters to be printed, and then % symbols to indicate where the other arguments need to be added, and how they need to be printed as output. %d in this example tells the computer to print the variable as an integer.
The full command
printf("%d\t%d\n", fahr, Celsius);
tells to print two integers, fahr and Celsius, with a tab (\t) in between them.
Each % construction of the first argument correspondents with the respective following arguments. They need to match by number and type or the output will be messy.
K&R said it before: printf is not part of C. C itself does not define output or input. Printf \is part of a standard library of functions, which has it's origin in the Unix OS.
The behavior of printf is defined in the ANSI standard and therefor its properties are the same for any compiler that follows the standard.
We will first concentrate on the language itself, the writers state, and only talk more about input and output later in the book. Especially the topic of formatted input will be suspended until then.
The program to convert Fahrenheit to Celsius does is not very good because of two reasons:
1. The numbers are not right aligned. We can fix this if we add width to each %d argument. For example:
printf("%3d %6d\n", fahr, celsius);
Second, a more serious issue:
2. Because we have used integer arithmetic the Celsius temperatures are not accurate: the program lists 0 degree Fahrenheit as -17 degree Celsius, while in fact 1 degree Fahrenheit is -17.18 degrees Celsius. To fix this we should use floating-point arithmetic instead of integer.