How to Convert an Integer to a String in C? Last Updated : 21 May, 2025 Comments Improve Suggest changes 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 How to Convert a String to a Char Array in C? In C, the only difference between the string and a character array is possibly the null character '\0' but strings can also be declared as character pointer in which case, its characters are immutable. In this article, we will learn how to convert a string to a char array in C.The most straightforwa 2 min read Convert String to int in C In C, we cannot directly perform numeric operations on a string representing a numeric value. We first need to convert the string to the integer type. In this article, we will discuss different ways to convert the numeric string to integer in C language.Example:Input: "1234"Output: 1234Explanation: 6 min read Convert string to integer without using any in-built functions Given a string str, the task is to convert the given string into the number without using any inbuilt function. Examples: Input: str = "985632" Output: 985632 Explanation: Given input is in string form and returned output is in integer form. Input: str = "123" Output: 123 Explanation: Given input is 10 min read How to Append a Character to a String in C? In this article, we will learn how to append a character to a string using the C program.The most straightforward method to append a character to a string is by using a loop traverse to the end of the string and append the new character manually.C#include <stdio.h> void addChar(char *s, char c 3 min read Converting String to Long in C Here, we will see how to build a C Program For String to Long Conversion using strtol() function. Syntax: long int strtol(char *string, char **ptr, int base)The first argument is given as a stringThe second argument is a reference to an object of type char*The third argument denotes the base in whic 4 min read How to Reverse a String in C? In C, a string is a sequence of characters terminated by a null character (\0). Reversing a string means changing the order of the characters such that the characters at the end of the string come at the start and vice versa. In this article, we will learn how to reverse a string in C. Example: Inpu 2 min read Array of Pointers to Strings in C In C, arrays are data structures that store data in contiguous memory locations. Pointers are variables that store the address of data variables. We can use an array of pointers to store the addresses of multiple elements. In this article, we will learn how to create an array of pointers to strings 2 min read C Program For Long to String Conversion To convert the long to string in C language we will use the following 2 approaches: Using Macros with sprintfUsing sprintf Input: long = 1234 Output: string 12341. Using Macros and sprintf C // C Program for Long to // String Conversion #include <stdio.h> #include <string.h> #define Max_ 1 min read How to Find Length of a String Without string.h and Loop in C? C language provides the library for common string operations including string length. Otherwise, a loop can be used to count string length. But is there other ways to find the string length in C apart from above two methods. In this article, we will learn how to find length of a string without strin 2 min read Like