Atof, atoi, atol functions – Zilog Z80380 User Manual
Page 70

Library Functions
Run Time Environment
4–6
UM004001-COR1103
atof, atoi, atol
FUNCTIONS
Header file statement:
#include
Syntax:
double atof
(const char *string);
int atoi
( const char *string );
long atol
( const char *string );
These functions convert a character string to a double-precision floating-point value (atof),
an integer value (atoi), or a long integer value (atol). The input string is a sequence of charac-
ters that can be interpreted as a numerical value of the specified type.
The function stops reading the input string at the first character that it cannot recognize as
part of a number. This character may be the null character (‘\0’) terminating the string.
The atof function expects string to have the following form:
[whitespace] [sign] [digits] [.digits] [ {d | D | e | E }[sign]digits]
A whitespace consists of space and/or tab characters, which are ignored; sign is either plus
(+) or minus (-); and digits are one or more decimal digits. If no digits appear before the dec-
imal point, at least one must appear after the decimal point. The decimal digits may be fol-
lowed by an exponent, which consists of an introductory letter ( d, D, e, or E) and an
optionally signed decimal integer.
The atoi and atol functions do not recognize decimal points or exponents. The string argu-
ment for these functions has the form
[whitespace] [sign]digits
where whitespace, sign, and digits are exactly as described above for atof.
Return Value
Each function returns the double, int, or long value produced by interpreting the input char-
acters as a number. The return value is 0 (for atoi), 0L (for atol), and 0.0 (for atof) if the input
cannot be converted to a value of that type.
•
The return value is undefined in case of overflow.
Parameter
Description
string
String to be converted