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