Salem, are you on a 64bit system?
Bug 6453 – scanf integer overflow handling different between 32bit and 64bit
Bye, Andreas
Type: Posts; User: AndiPersti
Salem, are you on a 64bit system?
Bug 6453 – scanf integer overflow handling different between 32bit and 64bit
Bye, Andreas
Interesting. When I run your code I get:
$ ./foo
2147483647
9223372036854775807
Enter number: 2147483648
Number out of range, try again: Numerical result out of range
Enter number:...
You're right. I haven't read the man-page carefully enough:
So ERANGE for sscanf() only works with the GNU C Library.
Bye, Andreas
My code is tolerant and accepts a number if the input starts with it and discards any following characters.
If you only want "clean" numbers (nothing before and after) I suggest a combination of...
Have you ever heard of the KISS principle?
A simple do-while-loop is all you need:
#include <stdio.h>
#include <stdlib.h>
int main()
{