CKTIS / C
strtoull — text to unsigned long long
strtoull converts an initial string portion to unsigned long long; endptr detects missing conversion and remaining text.
Version: C23; repository compiler flag, production runtime not attested
Syntax
#include <stdlib.h>
unsigned long long int strtoull(const char *restrict nptr, char **restrict endptr, int base);strtoull from <stdlib.h> skips leading whitespace and accepts + or -. base is 2–36 or 0 for automatic base detection. C23 includes 0b/0B prefixes; runtime support is not attested.
With non-null endptr, *endptr identifies the first unconsumed character; no conversion returns 0 with *endptr == nptr. Clear errno beforehand: overflow returns ULLONG_MAX with ERANGE. The result alone cannot validate input.
Minus is not rejected: "-1" produces ULLONG_MAX. Check the sign separately when negative inputs are forbidden. Complete validation also requires checking the string's end.
Examples
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
const char *text = "12345";
char *end;
errno = 0;
unsigned long long value = strtoull(text, &end, 10);
if (end == text || errno == ERANGE || *end != '\0') {
puts("invalid");
return 1;
}
printf("%llu\n", value);
return 0;
}
Result
12345
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.