Standards / Extensions | C or C++ | Dependencies |
---|---|---|
z/OS® UNIX | both | z/OS V1R5 |
#define _OPEN_SYS_ITOA_EXT
#include <stdlib.h>
char * ulltoa(uint64_t ll, char * buffer, int radix);
Compile Requirement
Use of this function requires the long long data type. See z/OS XL C/C++ Language Reference for information on how to make long long available.
(void) sprintf(buffer, "%llu", ll);
with
buffer the returned character string. When the radix is OCTAL, ulltoa()
formats uint64_t ll into an octal constant. When the radix is HEX,
ulltoa() formats uint64_t ll into a 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.
This is a non-standard function. Even though the prototype given is commonly used by compilers on other platforms, there is no guarantee that this function will behave the same on all platforms, in all cases. You can use this function to help port applications from other platforms, but you should avoid using it when writing new applications, in order to ensure maximum portability.
/* CELEBU12
This example reads uint64_t and formats it to a decimal,
octal, hexadecimal constants converted to a character string.
*/
#define _OPEN_SYS_ITOA_EXT
#include <stdio.h>
#include <stdlib.h>
int main ()
{
uint64_t i;
char buffer [sizeof(uint64_t)*8+1];
printf ("Enter a number: ");
if (scanf ("%llu",&i) == 1) {
ulltoa (i,buffer,DECIMAL);
printf ("decimal: %s\n",buffer);
ulltoa (i,buffer,HEX);
printf ("hexadecimal: %s\n",buffer);
ulltoa (i,buffer,OCTAL);
printf ("octal: %s\n",buffer);
}
return 0;
}
Output
decimal: 1234
hexadecimal: 4d2
octal: 2322