Format
#include <stdlib.h> char *_ltoa(long value, char *string, int radix);
Language Level: Extension
_ltoa converts the digits of the given long
integer value to a character string that ends with
a null character and stores the result in string.
The radix argument specifies the base of value; it must be in the range 2 to 36. If radix equals 10 and value
is negative, the first character of the stored string is the
minus sign (-).
Note: The space allocated for string must be large enough to hold the returned string. The function can return up to 33 bytes, including the null character (\0).
Return Value
_ltoa returns a pointer to string. There is no error return value.
Example
This example converts the long integer
-255L to a decimal, binary, and hex value, and stores its
character representation in the array buffer.
#include <stdio.h> #include <stdlib.h>
int main(void)
{
char buffer[35];
char *p;
p = _ltoa(-255L, buffer, 10);
printf("The result of _ltoa(-255) with radix of 10 is %s\n", p);
p = _ltoa(-255L, buffer, 2);
printf("The result of _ltoa(-255) with radix of 2\n is %s\n", p);
p = _ltoa(-255L, buffer, 16);
printf("The result of _ltoa(-255) with radix of 16 is %s\n", p);
return 0;
/****************************************************************
The output should be:
The result of _ltoa(-255) with radix of 10 is -255
The result of _ltoa(-255) with radix of 2
is 11111111111111111111111100000001
The result of _ltoa(-255) with radix of 16 is ffffff01
****************************************************************/
}
![]()
atol -- Convert Character
String to Long Integer
_ecvt -- Convert
Floating-Point to Character
_fcvt -- Convert
Floating-Point to String
_gcvt -- Convert
Floating-Point to String
_itoa -- Convert
Integer to String
strtol --
Convert Character String to Long Integer
_ultoa -- Convert
Unsigned Long Integer to String
wcstol --
Convert Wide-Character to Long Integer
<stdlib.h>