Convert array of chars to int

when i do

void adcWorker() {

  volts = analogRead(voltSense);

  float voltage = (volts) * (5.0 / 1023.0);   //FIXME: Scale properly to suit 1.25 - 6v input

  Serial.print("voltage: ");
  Serial.println(voltage);



  dtostrf(voltage, 10, 3, strBuf);

  size_t n = sizeof(strBuf) / sizeof(strBuf[0]);


  // for (size_t i = 0; i < n; i++) {
  //   Serial.println(strBuf[i]);


  // }


  for (size_t i = 0; i < n; i++)
  {
    if ( (strBuf[i] >= '0' && strBuf[i] <= '9') || strBuf[i] == '.')
    {
      Serial.print(strBuf[i]);
      Serial.print(" is in location: ");
      Serial.print(i);
      Serial.println("");


int j = atoi(strBuf[i]);

  Serial.print(strBuf[i]);
      Serial.print(" to integer is: ");
      Serial.print(j);
      Serial.println("");

    }

 }

  //val = atoi((char *)strBuf);



}

the output is:

[codevoltage: 0.71
0 is in location: 5
0 to integer is: 0
. is in location: 6
. to integer is: 0
7 is in location: 7
7 to integer is: 0
1 is in location: 8
1 to integer is: 0
4 is in location: 9
4 to integer is: 0
][/code]

when trying to convert the chars to ints, all that I get is zeros

e.g. 7 to integer is: 0

Why?

  int j = atoi(strBuf[i]);

atoi() expects a pointer to a string, you're passing it the value of a character

if you want to use atoi() you need to copy that one character to a string with a null termination.

a simpler approach is to subtract the value of '0' from the value of the character

e.g. 7 to integer is: 0

What you are doing is trying to convert '7' to an integer. gcjr has provided two solutions but the thread title says that you want to convert an array of chars to an int, not single characters

Check if you can learn something from the following sketch and then employ it to find what you are looking for (your sketch is slightly modified):

#define voltSense A0
char strBuf[5] = "";
void setup()
{
  Serial.begin(9600);
}

void loop()
{
  adcWorker();
  delay(3000);
}

void adcWorker()
{

  int volts = analogRead(voltSense);  //tested using 3.3V of UNO

  float voltage = (volts) * (5.0 / 1023.0);   //FIXME: Scale properly to suit 1.25 - 6v input

  Serial.print("voltage: ");
  Serial.println(voltage, 3); //3-digit after decimal point
  dtostrf(voltage, 1, 3, strBuf);//float voltage, digit before decimal point, digit after decimal point, 
  Serial.println(strBuf);  //shows: float volat
  //size_t n = sizeof(strBuf);// / sizeof(strBuf[0]);
  //Serial.println(n);
  float volt = atof(strBuf); //converting ASCII coded to float
  Serial.println(volt, 3); //shows: float voltage tested using 3.3V of UNO
}