Warning: implode(): Invalid arguments passed in /www/wwwroot/jobquiz.info/mdiscuss.php on line 336 Does there any function exist to convert the int or float to a string? ?->(Show Answer!)
1. Does there any function exist to convert the int or float to a string?
Ask Your Doubts Here
Comments
By: guest on 01 Jun 2017 06.02 pm
1. itoa() converts an integer to a string.
2. ltoa() converts a long to a string.
3. ultoa() converts an unsigned long to a string.
4. sprintf() sends formatted output to a string, so it can be used to convert any type of values to string type. #include<stdio.h> #include<stdlib.h> int main(void) { int num1 = 12345; float num2 = 5.12; char str1[20]; char str2[20]; itoa(num1, str1, 10); /* 10 radix value */ printf("integer = %d string = %s \n", num1, str1); sprintf(str2, "%f", num2); printf("float = %f string = %s", num2, str2); return 0; } // Output: // integer = 12345 string = 12345 // float = 5.120000 string = 5.120000
2. ltoa() converts a long to a string.
3. ultoa() converts an unsigned long to a string.
4. sprintf() sends formatted output to a string, so it can be used to convert any type of values to string type. #include<stdio.h> #include<stdlib.h> int main(void) { int num1 = 12345; float num2 = 5.12; char str1[20]; char str2[20]; itoa(num1, str1, 10); /* 10 radix value */ printf("integer = %d string = %s \n", num1, str1); sprintf(str2, "%f", num2); printf("float = %f string = %s", num2, str2); return 0; } // Output: // integer = 12345 string = 12345 // float = 5.120000 string = 5.120000