Domanda

I am writing a code in which I need to parse a string to a "long long int"

I used to use atoi when changing from string to int, I dont think it still work. What Can I use now?

--Thanks

È stato utile?

Soluzione

Use strtoll() (man page):

#include <stdlib.h>

long long int n = strtoll(s, NULL, 0);

(This is only available in C99 and C11, not in C89.) The third argument is the number base for the conversion, and 0 means "automatic", i.e. decimal, octal or hexadecimal are selected depending on the usual conventions (10, 010, 0x10). Just be mindful of that in case your string starts with 0.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top