converting char array (c string) to _int64 in C

Ahmed picture Ahmed · Oct 31, 2011 · Viewed 8.6k times · Source

I tried this function to convert a string to _int64 but it didn't work :

_int64 lKey = _atoi64("a1234");

lKey value is always zero and doesn't work except the string is only digits like "1234"

I read solutions using C++ string stream but I want to write my application in pure C

Answer

Constantinius picture Constantinius · Oct 31, 2011

The function does indeed work. As the documentation states:

Each function returns the __int64 value produced by interpreting the input characters as a number. The return value is 0 for _atoi64 if the input cannot be converted to a value of that type.

So you have to make sure that a correct string is passed. Otherwise, the return value will always be zero. "a1234" is not a correct string in terms of this function and pretty every "dump" parsing function will fail to parse it.