September 30, 2004
validating input with strtol (link)
http://home.att.net/~jackklein/c/code/strtol.html
A very common question from newcomers to C and C++ programming is how to validate input. They use the standard library functions and objects like scanf() or cin which work well if the input is well-formed and within range, but fail if the input is invalid. This can be a real problem when the input is coming from a user at a keyboard and the user types something unexpected!