What is atoi equivalent for 64bit integer(uint64_t) in C that works on both Unix and Windows?

JosephH picture JosephH · Sep 21, 2011 · Viewed 57.9k times · Source

I'm trying to convert 64bit integer string to integer, but I don't know which one to use.

Answer

cnicutar picture cnicutar · Sep 21, 2011

Use strtoull if you have it or _strtoui64() with visual studio.

unsigned long long strtoull(const char *restrict str,
       char **restrict endptr, int base);


/* I am sure MS had a good reason not to name it "strtoull" or
 * "_strtoull" at least.
 */
unsigned __int64 _strtoui64(
   const char *nptr,
   char **endptr,
   int base 
);