Saving Characters From SD Into a 2D Array

Hello! I am using the adafruit SD card breakout with an arduino Nano

I have a portion of my code that takes an array, splits up the numbers with comas and colons, changes them into strings, then saves it into the SD card. The original array looks like this:

int arr[2][6]={{4,6},{4,8},{5,6},{5,3}{0,0},{255,255}}

And what is saved to the SD card looks like this (this is when I take out the SD and open the TXT file on my laptop):

4:6,4:8,5:6,5:3,0:0,255:255,

Now my issue is reading from the SD card the above characters and then converting them back into an integer array.This is the code I am using to read from the SD:

 myFile=SD.open("PROG00.TXT");              //open file
 if (myFile) {                              //***if it opens***
  x=0;                                        //reset counting variables
  y=0;                                        //reset counting variables
    while (myFile.available()) {              //**While the file is available**
      buff=myFile.read();                        //read the file and save to the char "buff'
      if(buff==':'){                             //*if buff is a colon*
        arr1[x][y]=atoi(blockstring);                //change the string "blockstring" into an integer, and save it to the [x][y] index of the array
        y++;                                         //index up y
        i=0;                                         //reset the counting variable for "blocksting" to zero
        for(int e=0; e<= sizeof(blockstring);e++){   //this small for loop clears "blockstring" so its ready for the next number
          blockstring[e]=' ';
        }                                            //end for loop to clear blockstring
      }                                          //end "if buff is a colon"
      else if(buff==','){                        //*if buff is a comma*
        arr1[x][y]=atoi(blockstring);                //change the string "blockstring" into an integer, and save it to the [x][y] index of the array       
        x++;                                         //index up x
        i=0;                                         //reset the counting variable for "blocksting" to zero
        y=0;                                         //reset the indexing variable for the array to zero
        for(int e=0; e<= sizeof(blockstring);e++){   //this small for loop clears "blockstring" so its ready for the next number
          blockstring[e]=' ';
        }                                            //end for loop to clear blockstring
      }                                          //end "if buff is a comma"
      else{                                      //*if buff is not a comma or a colon*
        blockstring[i]=buff;                         //save the char "buff" to the string "blockstring" with i as the indexing number
        i++;                                         //index up i
      }                                          //end "if buff is not a comma or a colon"

    }                                       //End "While the file is available"
    myFile.close();                         //close the file                 
  }                                      //End "if the file opens"
 
    

    for (int i = 0; i <= 10; i++) {          //this code serial prints the newly made array
    for (int y = 0; y <= 1; y++) {
      Serial.print(arr1[i][y]); 
    }
  }

The result I get from the Serial Monitor is just an array full of zeros. Not the array from the SD card

Can't see all your variable definitions but with less code, variables and no colon you could take this approach:

struct DataSet
{
   byte num1;
   byte num2;
};

DataSet myData[6];
myData[0].num1 = 3; myData[0].num2 = 6;
myData[1].num1 = 4; myData[1].num2 = 8;
...

// reading the data from the SD card
byte bPos = 0;
File myFile=SD.open("PROG00.TXT");
if (!myFile)
  return;
while (myFile.available())
{
  myData[bPos].num1 = myFile.read();
  myData[bPos].num2 = myFile.read();
  bPos++;
  if (bPos > 5)
    break;
}
myFile.close();

I fixed it!

my code worked, I just didn't have this in the setup of my code:

if (!SD.begin(chipSelect)) {
return;
}

so the communication with the SD card wasn't happening at all