ltoa(), lltoa()

Convert a long integer into a string, using a given base

Synopsis:

#include <stdlib.h>

char* ltoa( long value,
            char* buffer,
            int radix );

char* lltoa( long long value, 
             char* buffer,
             int radix );

Since:

BlackBerry 10.0.0

Arguments:

value
The value to convert into a string.
buffer
A buffer in which the function stores the string. The size of the buffer must be at least 33 bytes when converting values in base 2 (binary).
radix
The base to use when converting the number. This value must be in the range:
2 ≤ radix ≤ 36
  

If the value of radix is 10, and value is negative, then a minus sign is prepended to the result.

Library:

libc

Use the -l c option to qcc to link against this library. This library is usually included automatically.

Description:

The ltoa() and lltoa() functions convert the given long integer value into the equivalent string in base radix notation, storing the result in the character array pointed to by buffer. A NUL character is appended to the result.

Returns:

A pointer to the result.

Examples:

#include <stdio.h>
#include <stdlib.h>

void print_value( long value )
{
    int base;
    char buffer[33];

    for( base = 2; base <= 16; base = base + 2 ) {
        printf( "%2d %s\n", base,
            ltoa( value, buffer, base ) );
    }
}

int main( void )
{
    print_value( 12765 );
    
    return EXIT_SUCCESS;
}

produces the output:

 2 11000111011101
 4 3013131
 6 135033
 8 30735
10 12765
12 7479
14 491b
16 31dd

Classification:

ltoa() is QNX 4; lltoa() is Unix

Safety:  
Cancellation point No
Interrupt handler Yes
Signal handler Yes
Thread Yes

Last modified: 2014-06-24



Got questions about leaving a comment? Get answers from our Disqus FAQ.

comments powered by Disqus