Was not sure what you are specifically looking for, below is a function you can pass input of form

1 2
3 4
5 6
...
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int * str_to_int(char *lines) {
    int *int_arr;
    int i, offset, index;
    // alloc mem for int arr
    int_arr = malloc(sizeof(int) * (strlen(lines) / 2));
    index = 0;
    // using sscanf() "convert" string to int
    while(sscanf(lines, "%d%n", &i, &offset) == 1) {
        // offset increments ptr to lines
        lines += offset;
        int_arr[index++] = i;
    }
    return int_arr;
}
Answer from Cathal OGrady on Stack Overflow
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ convert-a-string-to-integer-array-in-c-cplusplus
Convert a String to Integer Array in C/C++
#include <stdio.h> #include <string.h> void convertStringToArray(char str[], int arr[], int *size) { int i = 0, j = 0, num = 0; int len = strlen(str); for (i = 0; i <= len; i++) { // If current character is digit if (str[i] >= '0' && str[i] <= '9') { num = num * 10 + (str[i] - '0'); } // If comma or end of string else if (str[i] == ',' || str[i] == '\0') { arr[j] = num; j++; num = 0; } // Skip spaces } *size = j; } int main() { char str[] = "2, 6, 3, 14"; int arr[100]; int size = 0; int i, sum = 0; convertStringToArray(str, arr, &size); printf("arr[] = "); for (i = 0; i < size; i++) { printf("%d ", arr[i]); sum += arr[i]; } printf("\nSum of array is = %d\n", sum); return 0; }
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ dsa โ€บ convert-a-string-to-integer-array-in-c-c
Convert a String to Integer Array in C/C++ - GeeksforGeeks
June 14, 2023 - // C++ program of the above approach #include <iostream> #include <numeric> #include <regex> #include <vector> std::pair<std::vector<int>, int> convertAndSum(const std::string& str) { std::vector<int> arr; // Extract all the numbers using regular // expressions std::regex pattern("\\d+"); std::sregex_iterator it(str.begin(), str.end(), pattern); std::sregex_iterator end; while (it != end) { // Convert the extracted number into an // integer and add it to the array arr.push_back(std::stoi(it->str())); ++it; } // Calculate the sum of the array int arraySum = std::accumulate(arr.begin(), arr.end(
Discussions

How do I convert a string in C++ or C to an integer array? - Stack Overflow
How do I convert a string into an array of integers? Can I use sstream, because atoi doesn't work?! More on stackoverflow.com
๐ŸŒ stackoverflow.com
Converting string to integer array in c - Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most. Learn more about Collectives ... Bring the best of human thought and AI automation together at your work. Explore Stack Internal ... Save this question. Show activity on this post. I am newbie to this topic. I am trying to convert integer array to string... More on stackoverflow.com
๐ŸŒ stackoverflow.com
April 30, 2017
atoi - Best Way to Convert Array of Strings to Array of Int in C - Stack Overflow
My current problem is to read in an unknown number of integers from stdin. My approach is to use gets() to store the entire line as a char array (char str[50]). I am trying to parse the char array and convert each "string int" to an integer and store in an int array. More on stackoverflow.com
๐ŸŒ stackoverflow.com
October 23, 2016
c - Converting 'integer strings' to integer array - Stack Overflow
I'm trying to pass in an array of integers into my program. Is there a better way to convert it to integers? I'm currently getting an error: "Variable sized object may not be initialized" for(i = ... More on stackoverflow.com
๐ŸŒ stackoverflow.com
October 20, 2013
๐ŸŒ
Snipplr
snipplr.com โ€บ view โ€บ 79201 โ€บ convert-string-to-integer-array
Convert String to integer array - C Snipplr Social Repository
October 8, 2014 - C#, convert a double-null-terminated string to an array of strings. ... To store large numbers into integer array by converting a string into interegr array.
Top answer
1 of 6
5

As you said in the comments, you got a binary string and you want to convert it into integers. Use bitset for that:

std::istringstream is(str);
std::bitset<32> bits; // assuming each num is 32 bits long

while(is >> bits) {
    unsigned long number = bits.to_ulong();
    // now, do whatever you want with that long.
    v.push_back(number);
}

If you only have one binary number in that string str, you can get away with

unsigned long number = std::bitset<32>(str).to_ulong();

Converting that in C is also possible...

long value;
char const *c = str;
for(;;) {
    char * endp;
    value = strtol(c, &endp, 2);
    if(endp == c)
        break;

    /* huh, no vector in C. You gotta print it out maybe */
    printf("%d\n", value);
    c = endp;
}

atoi can't parse binary numbers. But strtol can parse them if you tell it the right base.

2 of 6
4

How exactly would you like the conversion to work? Do you simply want an array containing the ASCII value of each character in the array? (so "abc" becomes [97, 98, 99, 0])?

Or do you want to parse the string somehow? ("1, 2, 3" becomes an array [1, 2, 3])

In the first case, in C++, I'd do something like this:

struct convert {
  int operator()(char c) {
    return static_cast<int>(c);
  }
};

std::string str = "hello world";
std::vector<int> result;
std::transform(str.begin(), str.end(), std::back_inserter(result), convert())

Of course you could use a raw array instead of the vector, but since the length of the string is probably going to be variable, and then arrays are just asking for trouble.

If this wasn't what you wanted, you might want to edit your question to be more specific.

๐ŸŒ
Medium
medium.com โ€บ @vikas234mv โ€บ convert-a-string-to-integer-array-in-c-c-58f427979e96
Convert a String to Integer Array in C/C++ | by Vikas | Medium
July 8, 2026 - #include <iostream> #include <vector> ... tokens. Each token representing a number is converted into an integer using the atoi() function....
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ c language โ€บ convert-string-to-int-in-c
Convert String to int in C - GeeksforGeeks
July 23, 2025 - There are 4 methods to convert a string to int which are as follows: ... The atoi() function in C takes a character array or string literal as an argument and returns corresponding value as integer.
Find elsewhere
๐ŸŒ
Udemy
blog.udemy.com โ€บ home โ€บ it & development โ€บ software development โ€บ c string to int: simple ways to convert to numeric values
C String to Int: Simple Ways to Convert to Numeric Values - Udemy Blog
April 14, 2026 - 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.
Top answer
1 of 2
1

Use these functions:

#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>

typedef int16_t gint16;  // define gint16 if not compiling with glib.h

char *gint16_to_string(gint16 *p, int n) {
    char *str = malloc(n * 4 + 1);
    if (str) {
        for (int i = 0; i < n; i++) {
            snprintf(str + i * 4, 5, "%04X", p[i] & 0xFFFF);
        }
    }
    return str;
}

void string_to_gint16(gint16 *p, int n, const char *str) {
    if (str) {
        for (int i = 0; i < n; i++) {
            unsigned int x = 0;
            sscanf(str + i * 4, "%4x", &x);
            p[i] = (gint16)x;
        }
    }
}

int main(void) {
    gint16 frame[5] = { 10, 2, 3, 7, 5 };

    // encoding in hexadecimal
    char *str = gint16_to_string(frame, 5);
    printf("encoded string: %s\n", str);

    // from hexa string to 16 bit integer array
    gint16 n_oframe[5];
    string_to_gint16(n_oframe, 5, str);

    printf("n_oframe: ");
    for (int i = 0; i < 5; i++) {
        printf("%d, ", n_oframe[i]);
    }
    printf("\n");

    free(str);
    return 0;
}
2 of 2
1

The commenters found most of it, so to put it all together

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>

// ALL CHECKS OMMITTED!

int main()
{
  int16_t frame[5] = { 10, 2, 3, 7, 5 };
  // hexadecimal string = 2 characters plus NUL
  // sizeof(char) == 1, if compiler is standard compliant
  char *str = malloc(3 * (sizeof(frame)/sizeof(frame[0]) +1));
  char *strp = str;
  size_t j;
  for (j = 0; j < sizeof(frame)/sizeof(frame[0]); j++) {
    // again: hexadecimal string = 2 characters plus NUL
    snprintf(strp, 3, "%02x", frame[j]);        //hexadecimal 
    strp += 2;
  }
  // we need a pointer to the start of the string to free it later
  strp = str;
  // let's see if we gott all of them
  printf("str = %s\n",str);
  // from hexa string to 16 bit integer array
  int16_t n_oframe[5];
  size_t i_m;
  // and again: hexadecimal string = 2 characters plus NUL
  // a simple char d[3]; would have been more than suffcient
  // for the task, but if stack is precious...
  char *d = (char *) malloc(3);
  for (i_m = 0; i_m < 5; i_m++) {
    // it's always the same, just do it once at the beginning
    //char *d = (char *) malloc(3);
    strncpy(d, str, 2);
    // atol() is for base 10 input only, use strtol() instead
    n_oframe[i_m] = (int16_t)strtol(d,NULL,16);
    str = str + 2;
    //free(d);
  }
  for (j = 0; j < 5; j++) {
     printf("%d ", n_oframe[j]);
  }
  putchar('\n');

  free(d);
  free(strp);
  exit(EXIT_SUCCESS);
}

I changed gint16 to int16_t because I do not know what that is supposed to be. You can most likely replace it with gint16 without problems.

๐ŸŒ
Quora
quora.com โ€บ How-can-I-convert-a-string-to-an-int-array-in-C
How to convert a string to an int array in C# - Quora
Quora is a place to gain and share knowledge. It's a platform to ask questions and connect with people who contribute unique insights and quality answers.
๐ŸŒ
Stack Overflow
stackoverflow.com โ€บ questions โ€บ 39478435 โ€บ best-way-to-convert-array-of-strings-to-array-of-int-in-c
atoi - Best Way to Convert Array of Strings to Array of Int in C - Stack Overflow
October 23, 2016 - 1" /* ... */ printf("Enter integers: "); fgets(string, sizeof(string), stdin); char *endptr, *ptr = string int count = 0; while (*ptr != '\0') { if (isdigit(*ptr)) { numbers[count++] = strtol(ptr, &endptr, 10); } else { endptr = ptr + 1; } ptr ...
๐ŸŒ
Cprogramming
cboard.cprogramming.com โ€บ c-programming โ€บ 4073-string-integer-array.html
String To Integer Array!!!! - C Board - Cprogramming.com
what about 'atoi' it changes a string into an integer value. If it does not convert to a integer, it returns zero.
๐ŸŒ
Cplusplus
cplusplus.com โ€บ forum โ€บ beginner โ€บ 79987
convert string to int array? - C++ Forum
Hi, I'm grabbing an 8 bit integer from a file using an ifstream object and assigning it to a string. Example, I'm grabbing 10101010 from a file and assigning it to stringName. the problem is, I MUST convert stringName to an int array, where arrayName[0]=1, arrayName[1]=0, arrayName[2]=1 etc. Can anyone PLEASE show me code how to do this?
๐ŸŒ
Linus Tech Tips
linustechtips.com โ€บ software โ€บ programming
C# Converting String Array to Int Array - Programming - Linus Tech Tips
January 26, 2017 - Hello, I have this line of code. DataValues_int = DataValues_raw.Select(s => int.Parse(s)).ToArray(); but I am getting "Exception thrown: 'System.OverflowException' in mscorlib.dll" The raw array has text in it. Which are actually numbers. So i want them to convert to ints so i can work with t...
๐ŸŒ
WsCube Tech
wscubetech.com โ€บ resources โ€บ c-programming โ€บ programs โ€บ string-to-int
How to Convert String to Int in C? 5 Ways With Code
September 17, 2026 - Learn five easy ways to convert a string to an int in C using atoi(), strtol(), sscanf(), and manual conversion. Includes code examples!