totn C Functions

C Language: atoi function
(Convert String to Integer)

In the C Programming Language, the atoi function converts a string to an integer.

The atoi function skips all white-space characters at the beginning of the string, converts the subsequent characters as part of the number, and then stops when it encounters the first character that isn't a number.

Syntax

The syntax for the atoi function in the C Language is:

int atoi(const char *nptr);

Parameters or Arguments

nptr
A pointer to a string to convert to an integer.

Returns

The atoi function returns the integer representation of a string. The atoi function skips all white-space characters at the beginning of the string, converts the subsequent characters as part of the number, and then stops when it encounters the first character that isn't a number.

Required Header

In the C Language, the required header for the atoi function is:

#include <stdlib.h>

Applies To

In the C Language, the atoi function can be used in the following versions:

  • ANSI/ISO 9899-1990

Similar Functions

Other C functions that are similar to the atoi function:

See Also

Other C functions that are noteworthy when dealing with the atoi function: