Bug in scanf?

Anders Magnusson <[email protected]> Mon, 8 Dec 2025 20:45:00 +0100
Newsgroups gmane.os.netbsd.devel.userlevel
Message-ID <[email protected]>
I just stumbled over something which may be a bug in scanf()...?
This example is in C99 7.19.6.2 clause 20.

This lines;

     int count; float quant; char units[21], item[21];
     count = sscanf("100ergs of energy\n",  "%f%20s of %20s", &quant, 
units, item);

Should have a count of 0;
     count = 0; // "100e" fails to match "%f"

but; our sscanf return 3 and sets the values like this:
     count=3 quant=100.000000 units=ergs item=energy

Huh?
And this bug seems to have been in the scanf code ~forever.
Same problem on MacOS (have the same scanf I suppose).
Linux (with glibc) also returns 3 but eats the 'e' in ergs.

So?  Any comments?

-- Ragge