I have used the function atoi
to convert character strings to int
and it\'s working fine but when I gave
num = atoi (argv[1]) ;
/
You've run into the maximum value of an integer. Since atoi
returns an int
, it is limited to the size of an integer on your machine. It looks like your machine uses 32-bit int
s.
In case you missed it (it's easy to miss), 2147483647 = (2 ^ 31) - 1. Remember that int
s can be negative, and the leftmost bit is the sign bit in that case. That's why you see the number being "limited" to 2147483647.
Try defining num
as unsigned int
instead of int
, and use strtoul
instead of atoi
.