Submitter: Fred J. Tydeman
Submission Date: 2016-03-29
Document: WG14 N2033
Example 5 in 22.214.171.124 fscanf appears to be wrong.
EXAMPLE 5 The call:
#include <stdio.h> /* ... */ int n, i; n = sscanf("foo % bar 42", "foo%%bar%d", &i);
will assign to n the value 1 and to i the value 42 because input white-space characters are skipped for both the % and d conversion specifiers.
Yet, my reading of the standard says it should fail (which is what most implementations do).
I can see that #6 causes the 'foo' directive to match 'foo' of the input.
I can see that #8 causes the '%%' directive to match '%' and its leading spaces (but not trailing spaces) of the input.
I cannot find anything that causes the spaces between the '%' and the 'bar' of the input to be matched when the 'bar' directive is processed, so the scan fails.
#15 is the only mention of trailing white space that I see.
Suggested Technical Corrigendum
In 126.96.36.199#22, change:
n = sscanf("foo % bar 42", "foo%%bar%d", &i);
n = sscanf("foo % bar 42", "foo%% bar%d", &i);
That is, add a space between '%%' and 'bar'.