Standards / Extensions | C or C++ | Dependencies |
---|---|---|
z/OS® UNIX | both | z/OS V1R5 |
#define _OPEN_SYS_ITOA_EXT
#include <stdlib.h>
char * lltoa(int64_t ll, char * buffer, int radix);
(void) sprintf(buffer, "%lld", ll);
with
buffer the returned character string. When the radix is OCTAL, lltoa()
formats int64_t ll into an unsigned octal constant. When
the radix is HEX, lltoa() formats int64_t ll into an unsigned
hexadecimal constant. The hexadecimal value will include lower case
abcdef, as necessary.String pointer (same as buffer) will be returned. When passed an invalid radix argument, function will return NULL and set errno to EINVAL.
/* CELEBL30
This example reads an int64_t and formats it to decimal, unsigned
octal, unsigned hexadecimal constants converted to a character
string.
*/
#define _OPEN_SYS_ITOA_EXT
#include <stdio.h>
#include <stdlib.h>
int main ()
{
int64_t i;
char buffer [sizeof(int64_t)*8+1];
printf ("Enter a number: ");
if (scanf ("%lld",&i) == 1) {
lltoa (i,buffer,DECIMAL);
printf ("decimal: %s\n",buffer);
lltoa (i,buffer,HEX);
printf ("hexadecimal: %s\n",buffer);
lltoa (i,buffer,OCTAL);
printf ("octal: %s\n",buffer);
}
return 0;
}
Output
decimal: 1234
hexadecimal: 4d2
octal: 2322