ltoa() long integer to string conversion - C-Tutorial

Latest

Saturday, 8 October 2016

ltoa() long integer to string conversion

ltoa() function:           ltoa() function converts a long integer value into a string.  The general format of the ltoa() function is:


                        Syntax:           char *  ltoa(long int  , char[] , int);
Where,
            First argument is a long integer value used for conversion.
            Second argument is a string used to store the conversion value.

            Third argument is an integer value that represents format of conversion such as decimal, octal and hexa-decimal format.

/* EXAMPLE PROGRAM FOR atol() FUNCTION */

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

main()
{
    long  a=10000000;
    char buffer[50];
    ltoa(a,buffer,2);   // here 2 means binary
    printf("Binary value = %s\n", buffer);

    ltoa(a,buffer,10);   // here 10 means decimal
    printf("Decimal value = %s\n", buffer);

    ltoa(a,buffer,16);   // here 16 means Hexadecimal
    printf("Hexadecimal value = %s\n", buffer);
}

No comments:

Post a Comment