> Can the atoi() function be used safely.

> If not can anyother function which is not having this problem
strtol() is the only safe standard function for converting a string to an int.

> This is happening in Windows XP and not in Linux using gcc.
Which only goes to show that when used outside the spec, anything can happen, including the apparent "correct" result.
AFAIK, atoi() is just a wrapper around strtol() in glibc.

> The input is being truncated to the max upper limit of the 2 byte interger value.
Huh? what compiler are you using?
All the compilers for the operating systems you've mentioned should have 4-byte integers.