by Sai gowtham

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);
}

Top Udemy Courses

JavaScript - The Complete Guide 2021 (Beginner + Advanced)
JavaScript - The Complete Guide 2021 (Beginner + Advanced)
64,026 students enrolled
52 hours of video content
View Course
React - The Complete Guide (incl Hooks, React Router, Redux)
React - The Complete Guide (incl Hooks, React Router, Redux)
284,472 students enrolled
40 hours of video content
View Course
Vue - The Complete Guide (w/ Router, Vuex, Composition API)
Vue - The Complete Guide (w/ Router, Vuex, Composition API)
152,857 students enrolled
48.5 hours of video content
View Course