In the C programming language, a string such as "2147483649"
overflows as an int since the largest unsigned int is 2147483647
. When I want to convert strings of integers to int
s, how do I go about checking for these overflow cases?
I can't just check if it is >=-(2^32-1)
and <= (2^32-1)
since the process of converting this string to an int
(eg atoi()
) already changes this value. Is there an easy way instead of checking the number of digits of the string before converting and also each digit at a time to make sure it's within the range of int
s?