2-D array error invalid types 'char[int]'

I am trying to read in data in this form xxxx.xx,N,xxxxx.xx,W and parse it using the commas as dilimeters.
To do this I am using a 2-d arrray and a nested for loop. I am getting this error: invalid types ‘char[int]’ for array subscript
The error is given on this line buffer1_gps = Serial.read();
```
*int x = 0, y = 0, i = 0;
 char buffer_gps[4][6];
 char buffer1_gps[13];
  char buffer[13];

while(Serial.available()) //Read 13 bytes into array
    {
      for(i=0; i<13; i++)
      {
        buffer1_gps[i] = Serial.read();
      }
    }
   
    for(y=0; y<4; y++)
    {
      for(x=0; buffer1_gps != ‘,’; x++)
      {
        buffer[y] = buffer1_gps;
      }
    }
      //desired_heading = atoi(buffer); //convert array into int
      Serial.println();
      Serial.print("buffer1_gps = ");
      Serial.println(buffer1_gps);
      Serial.print("buffer_gps[0] = ");
      Serial.println(buffer_gps[0]);
      Serial.print("buffer_gps[1] = ");
      Serial.println(buffer_gps[1]);
      Serial.print("buffer_gps[2] = ");
      Serial.println(buffer_gps[2]);
      Serial.print("buffer_gps[3] = ");
      Serial.println(buffer_gps[3]);*
```
Thanks for the help!

  buffer[y][x] = buffer1_gps[x];

Where is “buffer” declared?

while(Serial.available()) //Read 13 bytes into array
     {
       for(i=0; i<13; i++)
       {
         buffer1_gps[i] = Serial.read();
       }
     }

That may cause you some grief later.

Buffer is declared outside of the switch statement in the beginning of my void loop. edited the code

So why didn't you post it?

Fixed it. The unabridged code is big and mostly unimportant, I missed that variable.

…which is why we ask you to post all your code.

Still better watch out for the Serial.read loop to bite you in the ass.

I am trying to read in data in this form xxxx.xx,N,xxxxx.xx,W and parse it using the commas as dilimeters.

The people that wrote the strtok() function put a lot of work into it, so you wouldn't have to. Why reinvent the wheel?

Wow i thought I was being briliant. I think that function is exactly what I need, but im not really sure how to use the pointer to do what I need it to do. In the end I want to take this data xxxx.xx,n,yyyyy.yy,s and convert it to

float xxxx.xx
char n
float yyyyy.yy
char s

How do I use strtok to do this?

char buffer_gps[21];
  char * pch;
Serial.println("Enter Gps Coordinates");
   
     while(Serial.available() < 21) //Wait for 13 bytes to be availible
     {
       delay(5);
     }
   while(Serial.available()) //Read 3 bytes into array
     {
       for(i=0; i<21; i++)
       {
         buffer_gps[i] = Serial.read();
       }
     }
     
  Serial.println();
  Serial.print("This is in buffer_gps ");
  Serial.println(buffer_gps);
  
  pch = strtok (buffer_gps,",");
  while (pch != NULL)
  {
    Serial.println(pch);
    pch = strtok (NULL, ",");
  }

This is the solution. Thanks for the help.

  lat = atof(strtok(buffer_gpsg, ","));
  n_s =  *strtok(NULL, ",");
  lon = atof(strtok (NULL, ","));
  e_w =  *strtok(NULL, ",");

This is the solution. Thanks for the help.

Code:

lat = atof(strtok(buffer_gpsg, ",")); n_s = *strtok(NULL, ",");

The first statement will work, since the value in the token is converted to a float. The second statement will not, You need to copy the characters in the token into n_s (presuming that n_s is a character array). The strcpy() function would be useful.

It's always a good idea to test that the strtok() function returned a valid pointer before trying to dereference it. You are not, in this code snippet.