In C programming, the standard library function that converts a string to a long integer is strtol.
The function is declared in <stdlib.h> and has the form strtol(const char *str, char **endptr, int base). It skips leading whitespace, reads an optional sign and a valid integer representation, and returns the result as a long. The base argument allows decimal, hexadecimal, octal, or another base from 2 through 36; a base of 0 lets prefixes help determine the base.
The endptr parameter makes strtol more useful than simpler conversion routines. It can point to the first character not consumed, allowing a program to detect trailing text or determine where parsing stopped. Programs should also check errno for range errors, because values outside the long range produce LONG_MAX or LONG_MIN as appropriate.
The distractors differ in purpose. strtoul returns an unsigned long, atoi returns an int with limited error reporting, and sscanf performs formatted input parsing rather than being a dedicated string-to-long conversion function.