Looped Array to print as csv

if (anArray[r][1] ==1);

A good start but flawed

What should happen if the test returns true ?

As written you have explicitly told the program to do nothing, or to be more precise, to execute the code that follows the test up to the first semicolon it encounters, ie, do nothing.

In the code written above at the top of page.
Ignore the “;” I was writing from my phone not thinking sorry.

  int anArray[3][2] = {{12, 1}, {14, 0}, {16, 1}};

  byte bytesPerEntry = sizeof(anArray[0][0]);
  byte cols = (sizeof(anArray[0]) / bytesPerEntry);
  byte rows = ((sizeof(anArray) / cols) / bytesPerEntry);
  byte count = 0;
void setup()

{
  Serial.begin(115200);
}
void loop() 
{
  for (int r = 0; r < rows ; r++)
  {
    if (anArray[r][1] == 1)
    {
      count++;
      Serial.print(anArray[r][0]);
      if (r <= count)
      {
        Serial.print(",");
      }

      if (r == rows - 1)
      {
        count = 0;
      }
    }
  }
  Serial.println();
delay(500);
}

This returns the pin number with the issue

Why have count variable ?

With the example data

int anArray[3][2] = {{12, 1}, {14, 0}, {16, 1}};

what should the output look like ?

UKHeliBob: Why have count variable ?

With the example data

int anArray[3][2] = {{12, 1}, {14, 0}, {16, 1}};

what should the output look like ?

The output would be "12,16". I tried to make the count print the amount of commas but I cant forever for the life of me get the right amount. If the array reads:

int anArray[3][2] = {{12, 0}, {14, 0}, {16, 1}};

The output reads "16," where i don't want a comma at all

I think that something like this is more understandable

int anArray[2][3] = {{12, 13, 14}, {15, 16, 17}};
boolean needComma = false;

void setup()
{
  Serial.begin(115200);
  byte bytesPerEntry = sizeof(anArray[0][0]);
  byte cols = (sizeof(anArray[0]) / bytesPerEntry);
  byte rows = ((sizeof(anArray) / cols) / bytesPerEntry);
  for (int r = 0; r < rows ; r++)
  {
    for (int c = 0; c < cols; c++)
    {
      if (needComma)
      {
        Serial.print(",");
      }
      Serial.print(anArray[r][c]);
      needComma = true;
    }
  }
}

void loop()
{
}

Thanks UKHeliBob, Your a legend,this tormented me for a bit.
I modified the code a bit to suit being put in the loop as I will be using it in a xml for webserver to grab

  int anArray[6][2] = {{12, 1}, {14, 0}, {16, 1}};
  boolean needComma = false;

  byte bytesPerEntry = sizeof(anArray[0][0]);
  byte cols = (sizeof(anArray[0]) / bytesPerEntry);
  byte rows = ((sizeof(anArray) / cols) / bytesPerEntry);
  byte count = 0;
  
void setup()

{
  Serial.begin(115200);
}
void loop() 
{
  for (int r = 0; r < rows ; r++)
  {
    if (anArray[r][1] == 1)
    {

      if (needComma)
      {
        Serial.print(",");
      }
      Serial.print(anArray[r][0]);
      needComma = true;
    }
    if (r == rows - 1)
    {
      needComma = false; 
    }
  }
  Serial.println();
delay(500);
}