What is the best way in C to convert a number to a string?
Solution: Use sprintf() function.
#include<stdio.h> int main() { char result[50]; float num = 23.34; sprintf(result, "%f", num); printf("\n The string for the num is %s", result); getchar(); } |
chevron_right
filter_none
You can also write your own function using ASCII values of numbers.
Recommended Posts:
- Convert a floating point number to string in C
- gcvt() | Convert float value to string in C
- How to convert C style strings to std::string and vice versa?
- Converting string to number and vice-versa in C++
- Print substring of a given string without using any string function and loop in C
- Convert C/C++ code to assembly language
- Convert C/C++ program to Preprocessor code
- Program to Convert Hexadecimal to Octal
- How to find length of a string without string.h and loop in C?
- std::string class in C++
- Tokenizing a string in C++
- C | String | Question 14
- C | String | Question 13
- C | String | Question 12
- C | String | Question 15



