C – How to Convert String to int64_t

c++int64unix

How to convert program parameter from argv to int64_t? atoi() is suitable only for 32 bit integers.

Best Answer

There are a few ways to do it:

  strtoll(str, NULL, 10);

This is POSIX C99 compliant.

you can also use strtoimax; which has the following prototype:

 strtoimax(const char *str, char **endptr, int base);

This is nice because it will always work with the local intmax_t ... This is C99 and you need to include <inttypes.h>

Related Question