I personally don't like atoi function. I would suggest sscanf:

char myarray[5] = {'-', '1', '2', '3', '\0'};
int i;
sscanf(myarray, "%d", &i);

It's very standard, it's in the stdio.h library :)

And in my opinion, it allows you much more freedom than atoi, arbitrary formatting of your number-string, and probably also allows for non-number characters at the end.

EDIT I just found this wonderful question here on the site that explains and compares 3 different ways to do it - atoi, sscanf and strtol. Also, there is a nice more-detailed insight into sscanf (actually, the whole family of *scanf functions).

EDIT2 Looks like it's not just me personally disliking the atoi function. Here's a link to an answer explaining that the atoi function is deprecated and should not be used in newer code.

Answer from penelope on Stack Overflow
🌐
GitHub
gist.github.com › shaunlgs › 11196f2320e9013c000320f6e538a98b
Convert char array into int array in C. · GitHub
Save shaunlgs/11196f2320e9013c000320f6e538a98b to your computer and use it in GitHub Desktop. ... Convert char array into int array in C.
Discussions

C Converting Char array (strings) into int array - Stack Overflow
The reason you can't cast the numbers directly to integer references is because C allots a contiguous memory space to hold those 3 characters. Depending on the compiler you are using will determine the char size and int size. But if the chars are 8 bits each, then an array of 3 chars is 3 bytes. More on stackoverflow.com
🌐 stackoverflow.com
char - convert array of characters to array of integers in C - Stack Overflow
Sign up to request clarification or add additional context in comments. ... You forgot to null terminate each character... you will end up with an array of ints containing {1234, 234, 34, 4}. 2011-04-26T21:55:47.643Z+00:00 More on stackoverflow.com
🌐 stackoverflow.com
c - Convert char array to int array? - Stack Overflow
I'm beginner in C. I have an char array in this format for example "12 23 45 9". How to convert it in int array {12,23,45,9}? Thanks in advance. More on stackoverflow.com
🌐 stackoverflow.com
September 3, 2011
c++ - How to convert array of chars to array of ints? - Arduino Stack Exchange
Arduino is part of Stack Overflow’s open communities: specialist spaces where curiosity is welcome, knowledge is shared freely, and the best answers rise to the top. Find your community ... I have a rather newbie question but I can't figure it out. ... Are you sure those arrays contain what ... More on arduino.stackexchange.com
🌐 arduino.stackexchange.com
March 22, 2016
🌐
Coderanch
coderanch.com › t › 743639 › languages › convert-char-array-int-array
How to convert char array to int array in C (C / C++ forum at Coderanch)
June 27, 2021 - If that's what you're looking for then the int value of a char c in the range '0'..'9' is (c - '0'): Does that help? Edit: my first sentence appears to be what you're saying at the start of your post, but I'm a bit confused by your code. Hello again, sorry if I am confusing, what I mean is, that if I have an array of char that has the following: element 1 = 6, element 2 = 7, element 3 = 8 How do I convert that char array to a int array that has the same elements at the same place, so like I hope this makes more sense, else I will do my best to correct myself!
Find elsewhere
🌐
Cprogramming
cboard.cprogramming.com › c-programming › 170279-convert-character-array-integer-array-c.html
convert character array to integer array in c
April 11, 2016 - '0' is 48 so 48 - 48 is 0. '1' is 49 so 49 - 48 is 1. You can also use atoi the function to convert each character to an integer but the problem with this is that it does not protect you against overflow and underflow.(Now that I recall I think atoi uses the ASCII approach as well) My personal recommendation is to strtol as it tells you if you got an overflow or underflow and helps you when you are doing validation.
🌐
Cplusplus
cplusplus.com › forum › beginner › 185398
Char array to int array conversion - C++ Forum
this is the code i currently have but how do i turn the str array into an int array? ... https://www.quora.com/How-do-I-convert-a-string-into-an-integer-in-C++ http://www.cplusplus.com/doc/tutorial/typecasting/ ... You can add an integer to a char: str[4] += 5; I don't think that you need an int array.
🌐
CodingTechRoom
codingtechroom.com › question › convert-char-array-to-int-array-c
How to Convert a Char Array to an Int Array in C? - CodingTechRoom
char charArray[] = {'1', '2', '3'}; ... array to an int array in C involves iterating through each character of the char array and adjusting its value from ASCII to its integer equivalent....
🌐
Quora
quora.com › How-can-I-convert-a-char-array-into-an-into-int-array-in-C++
How to convert a char array into an into int array in C++ - Quora
Answer (1 of 4): Assuming your string contains numerals, and you want to convert them into an array of integers, one for one as a person would read them as numbers: The traditional way (C) is to tokenize the string in order left to right, into string tokens, convert and add to an array or vector...
🌐
GeeksforGeeks
geeksforgeeks.org › c++ › how-to-convert-char-array-to-int-in-cpp
How to Convert Char Array to Int in C++ - GeeksforGeeks
July 23, 2025 - // C++ Program to Convert Char Array to Int #include <iostream> #include <cstdlib> using namespace std; int main() { char str[] = "12345"; int num = atoi(str); cout << "The integer value is: " << num << endl; return 0; }
🌐
YouTube
youtube.com › watch
C - Converting char Array to int - YouTube
C - Converting char Array to int
Published: August 26, 2020
Views: 8K
🌐
Arduino Forum
forum.arduino.cc › forum 2005-2010 (read only) › software › syntax & programs
convert a char array of numbers into an integer - Syntax & Programs - Arduino Forum
June 24, 2010 - Hello everyone, I am having a rather noobish moment right now and could really use some help. like the title says, I am trying to convert a (section of a) character array of numbers into an integer. for example, assume I have the following: int pos; char command[4] = "b122" (can also be represented by: char command[4] = {'b','1','2','2'}) and assume that I want to convert the number section of that array into an actual 3-digit integer where i could set pos = 122; Essentially take comman...
🌐
Baeldung
baeldung.com › home › java › java array › convert char array to int array in java
Convert Char Array to Int Array in Java | Baeldung
January 8, 2024 - Typically, digit(char ch, int radix) is another method that we can use to address our central question. This method returns the numeric value of the given character based on the specified radix. Now, let’s exemplify how to use digit() to convert an array of characters into an array of integers:
🌐
Delft Stack
delftstack.com › home › howto › cpp › how to convert char array to int in cpp
How to Convert Char Array to Int in C++ | Delft Stack
February 12, 2024 - ... In the output, we can see the result of the converted integer value from the initial portion of the input string, which is 23323. std::atoi converts a C-style string (char array) to an integer.