db********@indiainfo.com (Bansidhar) wrote:
atoi() function seems not to have any support for Hex, octal number.
Usually when I read from a text file then it contain number like
0x232 etc. In this case atoi() fells. In case of itoa() there
is arrangement of passing the radix. Is there any historical
reason that it is not the case with atoi() ? Is there any alternate
function in C,C++ for atoi() to take care of all these things ?
There is no itoa() in ISO C, so any implementation which provides it as
an extension is free to define it as it wishes - it may be true that
your itoa() takes a radix, but this is by no means guaranteed.
As for atoi(), it is usually not a good function to use anyway. As you
note, it doesn't understand anything but decimal, but what's worse, it
has no facility to tell you where it stopped translating, and it will
cause undefined behaviour if you pass it a number too large for it. To
cure all these problems, use strtol() instead.
Richard