How to convert the Int to String in C
In this tutorial, we are going to learn about how to convert the int to a string in C.
Using sprintf() function
In C, we can use the sprintf()
function to convert an integer to a string.
Here is an example, that converts the int 123
to an string "123"
:
#include<stdio.h>
int main() {
int num = 123;
char str[5];
sprintf(str, "%d", num); // integer to string
printf("%s\n", str);
}
Output:
"123"