How to Convert an Integer to a String in C? Last Updated : 21 May, 2025 Summarize Comments Improve Suggest changes Share Like Article Like Report In C, integers can be represented as strings with each digit represented by corresponding numeric character. In this article, we will learn how to convert integers into the stringExamplesInput: 1234Output: "1234"Explanation: The integer 1234 is converted to the string "1234".Input: -567Output: "-567"Explanation: The integer -567 is converted to the string "-567".There are various methods that can be used to convert integer to a string in C:Manual Conversion Using LoopWe can convert an integer to a string manually by extracting each digit one by one and converting it to its corresponding character by using their ASCII code and storing it in the character array to form a string. C #include <stdio.h> #include <string.h> void intToStr(int N, char *str) { int i = 0; // Save the copy of the number for sign int sign = N; // If the number is negative, make it positive if (N < 0) N = -N; // Extract digits from the number and add them to the // string while (N > 0) { // Convert integer digit to character and store // it in the str str[i++] = N % 10 + '0'; N /= 10; } // If the number was negative, add a minus sign to the // string if (sign < 0) { str[i++] = '-'; } // Null-terminate the string str[i] = '\0'; // Reverse the string to get the correct order for (int j = 0, k = i - 1; j < k; j++, k--) { char temp = str[j]; str[j] = str[k]; str[k] = temp; } } int main() { int N = 1234; char str[12]; intToStr(N, str); printf("String: %s\n", str); return 0; } OutputString: 1234 Using sprintf() FunctionWe can also use the sprintf function in C to convert an integer to a string. The working of sprintf() function is similar is similar to printf() but instead of printing the output it stores the formatted output into a character array(string buffer). C #include <stdio.h> int main() { // Integer to be converted int N = 86; // Buffer to hold the resulting string char str[20]; // Converting integer to string using sprintf sprintf(str, "%d", N); printf("The integer %d converted to string is: %s\n", N, str); return 0; } OutputThe integer 86 converted to string is: 86 Note: We can also use the snprintf function which is similar to sprintf but with a buffer size limit, which helps prevent buffer overflows.Using itoa() Functionitoa() is a non-standard function available in some C compilers like MSVC, etc. It stands for Integer TO ASCII. It converts the given integer value to a null-terminated string and stores the result in the character array( buffer) defined by string parameter. C #include <stdio.h> #include <stdlib.h> int main() { int N = 1234; // Declare a character array 'str' t store the converted // string char str[12]; // Calling itoa() itoa(N, str, 10); printf("String: %s\n", str); return 0; } OutputString: 1234 Comment More infoAdvertise with us Next Article How to Convert an Integer to a String in C? A anjalibo6rb0 Follow Improve Article Tags : C Programs C Language C Examples Similar Reads C Programming Language Tutorial C is a general-purpose mid-level programming language developed by Dennis M. Ritchie at Bell Laboratories in 1972. It was initially used for the development of UNIX operating system, but it later became popular for a wide range of applications. Today, C remains one of the top three most widely used 5 min read Non-linear Components In electrical circuits, Non-linear Components are electronic devices that need an external power source to operate actively. Non-Linear Components are those that are changed with respect to the voltage and current. Elements that do not follow ohm's law are called Non-linear Components. Non-linear Co 11 min read Spring Boot Tutorial Spring Boot is a Java framework that makes it easier to create and run Java applications. It simplifies the configuration and setup process, allowing developers to focus more on writing code for their applications. This Spring Boot Tutorial is a comprehensive guide that covers both basic and advance 10 min read Class Diagram | Unified Modeling Language (UML) A UML class diagram is a visual tool that represents the structure of a system by showing its classes, attributes, methods, and the relationships between them. It helps everyone involved in a projectâlike developers and designersâunderstand how the system is organized and how its components interact 12 min read Backpropagation in Neural Network Back Propagation is also known as "Backward Propagation of Errors" is a method used to train neural network . Its goal is to reduce the difference between the modelâs predicted output and the actual output by adjusting the weights and biases in the network.It works iteratively to adjust weights and 9 min read 3-Phase Inverter An inverter is a fundamental electrical device designed primarily for the conversion of direct current into alternating current . This versatile device , also known as a variable frequency drive , plays a vital role in a wide range of applications , including variable frequency drives and high power 13 min read Polymorphism in Java Polymorphism in Java is one of the core concepts in object-oriented programming (OOP) that allows objects to behave differently based on their specific class type. The word polymorphism means having many forms, and it comes from the Greek words poly (many) and morph (forms), this means one entity ca 7 min read CTE in SQL In SQL, a Common Table Expression (CTE) is an essential tool for simplifying complex queries and making them more readable. By defining temporary result sets that can be referenced multiple times, a CTE in SQL allows developers to break down complicated logic into manageable parts. CTEs help with hi 6 min read What is Vacuum Circuit Breaker? A vacuum circuit breaker is a type of breaker that utilizes a vacuum as the medium to extinguish electrical arcs. Within this circuit breaker, there is a vacuum interrupter that houses the stationary and mobile contacts in a permanently sealed enclosure. When the contacts are separated in a high vac 13 min read Python Variables In Python, variables are used to store data that can be referenced and manipulated during program execution. A variable is essentially a name that is assigned to a value. Unlike many other programming languages, Python variables do not require explicit declaration of type. The type of the variable i 6 min read Like