strtol and strtod will take any amount of leading whitespace up to the number. It will then try to convert the number using a simple set of rules which allow leading zeros, +/-, and with wcstod, will accept ieee exponential notation (like "3.04e-12"). At the first sign of something NOT able to be converted (like the "1.0225 with junk" after the '5'), it stops converting and sets the second argument to the place where it stopped. This can then be used (as I show in the demo) to determine if the number completely converted, partially converted, or didn't convert at all. You can use the logic as above to re-prompt or warn the user, etc.
askmewhy25 like this