Match printf placeholders and arguments
Print a fan repair status
Two fans at bench D are ready after 1.5 hours. You already know the three value types; now focus on how one printf call places their values in a sentence.
c
#include <stdio.h>
int main(void) {
char bench = 'D';
int fans = 2;
double hours = 1.5;
printf("Bench %c: %d fans in %.1f hours\n", bench, fans, hours);
return 0;
}
The format string is the first argument. Read its conversions left to right and pair them with the arguments after the string:
| Conversion | Takes the value from | Prints |
|---|---|---|
%c | bench | D |
%d | fans | 2 |
%.1f | hours | 1.5 |
The commas separate arguments in C source. Spaces and punctuation inside the string become part of the output. \n finishes the line.
Run the example and check those three substitutions. The conversions must match the argument types; a mismatch can cause undefined behavior rather than a predictable formatting error. You'll write a radio test slip next, with different values but the same ordering rule.