You can use sprintf to do it, or maybe snprintf if you have it:

char str[ENOUGH];
sprintf(str, "%d", 42);

Where the number of characters (plus terminating char) in the str can be calculated using:

(int)((ceil(log10(num))+1)*sizeof(char))
Answer from cnicutar on Stack Overflow
Discussions

Beginner needing help, converting string to integer.
What you want is stoi but since you can't use it, you will have to manually parse the string. The way it goes is, we inspect each individual character in string and if it is between '0' (0x30) and '9' (0x39), we subtract '0' from this value. Say the character is '4' (0x34) so the arithmatic will be 0x34 - 0x30 = 4 We do this for every letter and we have integer value. So something like define variable num start for loop from 0 till str.size() if character is between '0' and '9', subtract '0' and save in val num = num*10 + val end for loop More on reddit.com
๐ŸŒ r/Cplusplus
17
4
November 9, 2022
How to convert integer to string in C?
Write a function to turn a number 0-9 into a char. Then write another function that uses it (hint: how could you break up the big number into digits) More on reddit.com
๐ŸŒ r/learnprogramming
9
2
November 29, 2017
is there any function in c to convert an integer to a string?
atoi() converts string to int, itoa() converts int to string. Still have no clue what 'a' is More on reddit.com
๐ŸŒ r/learnprogramming
38
19
December 30, 2022
Converting an int to a string
You appear to be neglecting to end your strings with null terminators. After the for loop in intToStr() add a line like result[i] = '\0';. What's happening is printf() is printing the string until it reaches the '\0' character, which is why you're getting those garbage values. Them being largely integer values and variants of Kw I suspect is a coincidence. Hope this helps. More on reddit.com
๐ŸŒ r/C_Programming
11
1
March 5, 2018
People also ask

Can I convert string to integer in C without using atoi function?
Yes, you can manually convert string to integer in C without using atoi function by implementing loops and ASCII character manipulation.
๐ŸŒ
wscubetech.com
wscubetech.com โ€บ resources โ€บ c-programming โ€บ programs โ€บ string-to-int
How to Convert String to Int in C? 4 Ways With Code
Can we convert floating-point strings to integers directly in C?
No, directly converting floating-point strings like "12.34" to integer is not possible. You must first convert them to float and then cast to integer.
๐ŸŒ
wscubetech.com
wscubetech.com โ€บ resources โ€บ c-programming โ€บ programs โ€บ string-to-int
How to Convert String to Int in C? 4 Ways With Code
Which header file is required for using the atoi() function?
To use the atoi() function for string to int conversion in C, you need the header file.
๐ŸŒ
wscubetech.com
wscubetech.com โ€บ resources โ€บ c-programming โ€บ programs โ€บ string-to-int
How to Convert String to Int in C? 4 Ways With Code
๐ŸŒ
Udemy
blog.udemy.com โ€บ home โ€บ c string to int: simple ways to convert to numeric values
C String to Int: Simple Ways to Convert to Numeric Values - Udemy Blog
October 25, 2025 - In this case, the string is an array of characters pointed to by num. Then, we calculate the length of the string using the strlen() function. Next, we loop through the string and convert the string into decimal values.
๐ŸŒ
WsCube Tech
wscubetech.com โ€บ resources โ€บ c-programming โ€บ programs โ€บ string-to-int
How to Convert String to Int in C? 4 Ways With Code
October 23, 2025 - Learn four easy ways to convert a string to an int in C using atoi(), strtol(), sscanf(), and manual conversion. Includes code examples!
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ c++ โ€บ convert-string-to-int-in-cpp
Convert String to int in C++ - GeeksforGeeks
September 19, 2025 - Non-digit characters result in a "Bad Input" message and terminate the program. The strtol function is used to converts a string to a long integer value, respectively.
Find elsewhere
๐ŸŒ
W3Schools
w3schools.com โ€บ c โ€บ c_type_conversion.php
C Data Type Conversion
C Errors C Error Challenge C Debugging C NULL C Error Handling C Input Validation ยท C Date C Random Numbers C Macros C Organize Code C Storage Classes C Bitwise Operators C Fixed-width Integers ... C Examples C Real-Life Examples C Exercises C Quiz C Code Challenges C Compiler C Syllabus C Study Plan C Interview Q&A C Certificate ... Sometimes, you have to convert the value of one data type to another type.
๐ŸŒ
ByteHide
bytehide.com โ€บ home โ€บ turning a string into an int in c#: full guide
Turning a String into an Int in C#: Full Guide - ByteHide
March 27, 2025 - Letโ€™s now dig deeper, delve into this world of string to int conversion. Fasten your seatbelts and read on. In C#, there are a few cool ways you can convert strings into integers. One such method is with the Parse() function.
๐ŸŒ
Codecademy
codecademy.com โ€บ article โ€บ how-to-convert-a-string-to-an-integer-in-c
How to Convert a String to an Integer in C++ | Codecademy
Dive into C#, a scalable programming language that is easy to read and maintain. ... In programming, receiving numbers as strings is common, especially when taking user input or reading from files. For example, a user might enter their age as "25" or the price of an item as "123". We must first convert these strings into integers to perform any mathematical operations, comparisons, or logical checks.
๐ŸŒ
Quora
quora.com โ€บ What-are-the-best-ways-to-convert-a-string-into-a-number-with-C
What are the best ways to convert a string into a number with C? - Quora
Answer (1 of 4): Using the built-in function atoi which means ASCII to integer: [code]#include int main() { char input[40]; scanf("%s", input); int number = atoi(input); printf("%d\n", number); return 0; } [/code]Creating the atoi function is ...
๐ŸŒ
Cprogramming
cboard.cprogramming.com โ€บ c-programming โ€บ 180727-convert-string-type-integer-type.html
Convert String type to Integer type
December 10, 2021 - int lower; char upper; int count; char die; char dieResult[4]; void printRandoms(int numFaces, int count) { int i; int num = 1; for (i = 0; i < count; i++) { num = rand() % numFaces + 1; ASCII = '0' + num; } memset(dieResult, 0, 4); //memset(result) is a char type i = log10(num); while (num != 0) { dieResult[i] = '0' + (num % 10); num /= 10; i--; } } void RNG() { UART_Puts(MS7); UART_Puts(MS6); UART_Get(); while (ASCII != '.') { die = die * 10 + (ASCII - '0'); UART_Get(); } upper = die; char *result; char buffer[20]; printRandoms(upper, 1); sprintf(buffer, "Rolled d%d: %s", upper, dieResult);
๐ŸŒ
Educative
educative.io โ€บ answers โ€บ how-to-convert-a-string-to-an-integer-in-c
How to convert a string to an integer in C
Lines 16-18: In this section we initializes a character array str3 with the value "99Hello!". Then it uses the atoi function to convert the string "99Hello!" to an integer. However, atoi stops converting when it encounters the first non-numeric character, which is 'H' in this case.
๐ŸŒ
Aticleworld
aticleworld.com โ€บ home โ€บ how to convert a string to an integer in c?
How to convert a string to an integer in C? - Aticleworld
October 18, 2022 - So letโ€™s see the first example using the atoi(). But the atoi() function has some limitations, so if you are not familiar with the atoi() function, then it is my suggestion that you should first read the atoi library function. You can check the other post โ€œHow to use atoi() and how to make ...