On Wed, Dec 10, 2025 at 10:07:15 +0100, Anders Magnusson wrote:
> The problem here is that it should be deterministic how the input will be
> parsed and not vary depending on which stdio implementation there is.
>
> The BSD stdio package gives this result:
> count=3 quant=100.000000 units=ergs item=energy
>
> Glibc gives this: (which also the original stdio package on 2BSD does)
> count=3 quant=100.000000 units=rgs item=energy
>
> But the C standard says that it should return count=0 which neither of them
> does.
>
> It would be interesting to know how some other (legacy) OSes parses, like
> Solaris? Any takers available? :-)
> Code snippet below:
>
> #include <stdio.h>
>
> main()
> {
> int count; float quant; char units[21], item[21];
> count = sscanf("100ergs of energy\n",
> "%f%20s of %20s", &quant, units, item);
> printf("count=%d quant=%f units=%s item=%s\n",
> count, quant, units, item);
> }
Solaris 11.3
count=3 quant=100.000000 units=ergs item=energy
-uwe