itoa(3C)
_________________________________________________________________
itoa function
Convert an integer to a character string.
_________________________________________________________________
Calling Sequence
int num;
char *itoa(), string;
itoa(num, string);
where num is of type int.
string is a byte pointer to a character array.
Description
Use the itoa function to convert an integer to an ASCII string.
If num is negative, the string will contain a maximum of 11
digits, including a minus sign, and will terminate in a null.
The include file stdio.h defines this function. It also defines
a macro L_itoa, which is replaced by 13, the maximum number of
characters itoa returns.
Returns
The itoa function returns the address of the string returned.
Related Functions
See also the atoi function.
Example
/* Program test for the itoa() function */
#include <stdio.h>
#define STRINGMIN 13
int i = 1, num;
char string[STRINGMIN];
main(argc, argv)
DG/UX 4.00 Page 1
Licensed material--property of copyright holder(s)
itoa(3C)
int argc;
char *argv[];
{
while (i < argc) {
num = atoi(argv[i]);
num *= i;
itoa(num, string);
printf("%s\n", string);
i++;
}
}
A call to the program test with the numbers 1, 2, 3, and 4
generates the output
1
4
9
16
DG/UX 4.00 Page 2
Licensed material--property of copyright holder(s)