MC logo
Problems With C I/O
[^] CSc 220 Home
[Introduction] [Boolean and Control] [Functions] [Arrays and Pointers] [Dynamic Arrays] [Array Errors] [Command Array] [Standard Containers] [Structs and Classes] [Automatic Pointer] [Multi-File Programs] [Copying Objects] [Templates] [Inheritance] [Plain C I/O] [Type Odds And Ends] [Plain C Strings] [File I/O]
[Hello, World! (Plain C)] [Average C I/O] [Printf Demo] [Problems With C I/O] [Looping On Read] [Convert To Upper Case] [Indent and Blank Remover] [Reading Lines] [Safer Line Reading] [Printing C++ Strings]
The type and number of % constructs must agree with the arguments given.

For scanf, you must get & in the right places.

Generally, compilers cannot check this.
At most a warning.

Extra arguments are just ignored.

Extra % specifications apply to junk following the arguments.

Extra % specifications in scanf use that junk as memory addresses.

Type mis-match can be very interesting.

Typically leads to run errors with opaque messages.

The gcc compiler writers have worked to aleviate some of these problems by giving warnings for bad printf calls. This requires the compiler to treat printf specially, which is a bit out of the spirit of the original C. Since it limits itself to warnings, it's not a violation of anything. If it did, it would probably be worth doing anyway.