How to convert a three dimensional string array into integer?

Using strtoi() or atoi(), comes to mind (include stdlib.h).

If the 3D part of it has your head stretched out sideways, post a very small example showing your problem, and what you want out of the data, for an example.

For example how to convert an array a[10][10][10] contains some 4 or 5 letters into an integer if i used atoi it will return only the first letter alone how can i extract remaining characters?

SHOW ME AN EXAMPLE OF THE ARRAY, AND IT'S DATA, AND WHAT YOU WANT OUT OF IT.

Your descriptions are not adequate in this case.

Don't worry about atoi(). Let's learn about the problem. The solution will present itself afterward, clearly.

Edited 6 Years Ago by Adak: n/a

For example the array a[10][5][4]="1->2"
then if i use atoi function it will return only 1 alone.. How can i extract remaining characters from it?

If you have a string, you can start atoi(), wherever you want. It just needs a pointer to the right starting point in the array

For example:

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

int main() {
  int i, n; 
  char snum[]="12345";

  printf("\n\n Original String: %s", snum);

  n = atoi(&snum[2]);
  printf("\n\n New Number is: %d", n);

  
  printf("\n\n\t\t\t     press enter when ready");

  i = getchar(); ++i;
  return 0;
}

Just make sure it has an end of string char: \0, at the end of the numbers. If it doesn't have that EOS char, then you'll have to do it in a loop with the specific indeces you want included.

This article has been dead for over six months. Start a new discussion instead.