convert line chars in array to int values

hello everyone, Ive parse data from sd file to array, but I cant use the elements in array as int value, Ive read about atoi() but doesnt work, please help on I can convert it, Thanks

this is my array

Array size is not fixed this is just an example

parameterArray[5] = {20, 25, 36, 45, 24};

Original string is
This is just one line as an example, number lines recorded are not fixed

6:47:25-13/8/2020 = 15
hr:min:sec-dt/mn/yr = sensor data

this is my parse function

void parseRecordArray() //split the parameters from each record
{
  for (int index = 0; index < recordNum; index++)
  {
    char * ptr; //pointer to current data
    ptr = strtok(recordArray[index], " = ");//find the "="
    ptr = strtok(NULL, ""); //get remainder of text
    parameterArray[index] = ptr + 1;  //remove space and save to array
    
  }
}

Your char array contains non-numeric characters. It can not be converted to int.

You can refer to how to convert string to integer

split the string into tokens using the string tokeniser
http://www.cplusplus.com/reference/cstring/strtok/

then use atoi() on the tokens containing digits

The second parameter to strtok is a list of delimiters (any one of the characters can match), not a string that must be present in its entirety in the destination.

You don’t give an example of your input string.

Your example doesn’t use strtok either (riven if it doesn’t work).

“Does not work” is not an adequate problem description.

This code can’t work...

parameterArray[index] = ptr + 1;  //remove space and save to array

...because you are assigning a pointer type to an integer array.

Because...

ptr = strtok(recordArray[index], " = ");//find the "="

Finds the first SPACE

This...

ptr = strtok(NULL, "");

Then finds the next delimiter, which is the “=“ sign
Therefore the next string returned is a empty string (everything between the first space and the equals).

I would suggest if possible you arrange for your input text to be in the format: “value=1234”
Instead of: “value = 1234”
And adjust your strtok processing accordingly.

If that’s not possible, then use strstr function instead to search for the whole “ = “ string.

what does your original string read from the SD card look like?
consider the following example using strtok()

/* strtok example */
#include <stdio.h>
#include <string.h>

int main ()
{
  char recordArray[] ="x = 10, y = 20, z = 30";
  char * pch;
  printf ("Splitting string \"%s\" into tokens:\n",recordArray);
  pch = strtok (recordArray," =,");
  while (pch != NULL)
  {
    int x=999;
    printf ("string found %s  ",pch);
    //x=atoi(pch);
    if(sscanf(pch,"%d",&x) == 1)   printf("integer = %d\n",  x);
    else                           printf("not integer\n");
     pch = strtok (NULL, " =,");
  }
  return 0;
}

gives

Splitting string "x = 10, y = 20, z = 30" into tokens:
string found x  not integer
string found 10  integer = 10
string found y  not integer
string found 20  integer = 20
string found z  not integer
string found 30  integer = 30

rather than using atoi() the example uses sscanf() which returns as a function results the number of sucessful conversions. this enables one to check if the string contained a valid integer

Thanks guys for your time

Original string is
This is just one line as an example, number lines recorded are not fixed

6:47:25-13/8/2020 = 15
hr:min:sec-dt/mn/yr = sensor data

strtok() is probably overkill - try using strstr() to look for the = then sscanf() to convert the following string to an int

int main ()
{
  char recordArray[] ="6:47:25-13/8/2020 = 15";
  char *pch;
  int x;
  printf ("string found %s  \n",recordArray);
  if((pch=strstr(recordArray,"=")) != NULL)
    if(sscanf(pch+1,"%d",&x) == 1)   printf("integer = %d\n",  x);
    else                           printf("not integer\n");
}

gives

string found 6:47:25-13/8/2020 = 15
integer = 15

If you're going to use sscanf() (which is "heavier" than strtok() anyway), you might as well use it to parse the entire string:

int hr, min, sec, dt, mn, yr, sensor_data
if (sscanf("6:47:25-13/8/2020 = 15", "%d:%d:%d-%d/%d/%d = %d", &hr, &min, &sec, &dt, &mn, &yr, &sensor_data) == 7) {
    // success
} else {
    // format error
}