Reputation: 1449
I have tried scanning long long
integers succesfully; but, I don't know how to scan larger integers than long long
. How would one scan Integers bigger than long long
in c? For instance, long long long
.
Upvotes: 1
Views: 11106
Reputation: 241731
There is no standard library function which is guaranteed to work with integers wider than long long int
. And there is no portable datatype which is wider than long long int
. (Also, long long int
is not guaranteed to be longer than 64 bits, which might also be the width of long
.)
In other words, if you want to work with very large integers, you'll need a library. These are typically called "bignum libraries", and you'll have little trouble searching for one.
Edit (including the theoretical possibility that the implementation has another integer type, as noted by @chux):
In theory, a C implementation may have integers wider than long long
, in which case the widest such integer types (signed and unsigned) would be called intmax_t
and uintmax_t
. Otherwise, and more commonly, intmax_t
and uintmax_t
are typedefs for long long
and unsigned long long
. You can use intmax_t
variables in scanf
and printf
functions by applying the length modifier j
. For example:
/* Needed for intmax_t */
#include <stdint.h>
#include <stdio.h>
int main() {
intmax_t probably_long_long;
if (1 == scanf("%jd", &probably_long_long))
printf("The number read was %jd\n", probably_long_long);
return 0;
}
Upvotes: 7