atoi(3C)
_________________________________________________________________
atoi function
Convert an ASCII string to type int.
_________________________________________________________________
Calling Sequence
int result, atoi();
char *string;
result = atoi(string);
where result is of type int.
string is a byte pointer to a character array that
contains optional spaces, an optional plus or minus
sign, and a string of digits.
Description
Use the atoi function to convert an ASCII string to a base 10
integer. The first nondigit terminates the scan.
The include file dg_stdio.h defines this function.
Returns
The atoi function returns the integer into which it converted the
ASCII string. No errors are flagged on the atoi function call.
If the string is not numeric, the atoi function returns 0.
Related Functions
See also the itoa, atof, atol, atou, sscanf, strtod, and strtol
functions.
Example
/* Program test for the atoi() function */
#include <stdio.h>
#include <math.h>
int result, atoi();
DG/UX 4.00 Page 1
Licensed material--property of copyright holder(s)
atoi(3C)
int i = 1;
main(argc, argv)
int argc;
char *argv[];
{
while (i < argc) {
printf("The result from %s is %d.\n", argv[i],
result = atoi(argv[i]));
i++;
}
}
If you call the program test with the input numbers
1776
-1776
1776
17-76
17LXX6
you generate the output
The result from 1776 is 1776.
The result from -1776 is -1776.
The result from 1776 is 1776.
The result from 17-76 is 17.
The result from 17LXX6 is 17.
DG/UX 4.00 Page 2
Licensed material--property of copyright holder(s)