Prev Next
C ltoa() function:
- ltoa() function in C language converts long data type to string data type. Syntax for ltoa() function is given below.
char *ltoa(long N, char *str, int base);
- “stdlib.h” header file supports all the type casting functions in C language.
Example program for C ltoa() function:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
#include <stdio.h> #include <stdlib.h> #include <string.h> int 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); return 0; } |
Output:
Binary value = 100110001001011010000000
Decimal value = 10000000
Hexadecimal value = 989680
|
Other inbuilt typecast functions in C programming language:
- Typecasting functions in C language performs data type conversion from one type to another.
- Click on each function name below for description and example programs.
Typecast function | Description |
atof() | Converts string to float |
atoi() | Converts string to int |
atol() | Converts string to long |
itoa() | Converts int to string |
ltoa() | Converts long to string |