Storing calibration tables on an SD card

Okay, I am learning.

I am taking small steps toward my bigger goal, but I am stuck. I don’t understand my problem, so I am having a hard time finding the right keywords to search for. Here is where I have gotten with my code:

#include <SdFat.h>
#include <SdFatUtil.h>
#include <string.h>

Sd2Card card;
SdVolume volume;
SdFile root;
SdFile file;

// store error strings in flash to save RAM
#define error(s) error_P(PSTR(s))

char sz[] = "3500,270,890,70,4";

char responseArray[] = {};
    

void error_P(const char* str) {
  PgmPrint("error: ");
  SerialPrintln_P(str);
  if (card.errorCode()) {
    PgmPrint("SD error: ");
    Serial.print(card.errorCode(), HEX);
    Serial.print(',');
    Serial.println(card.errorData(), HEX);
  }
  while(1);
}

void setup(void) {
  Serial.begin(9600);
//  Serial.println();
//  Serial.println("Type any character to start");
//  while (!Serial.available());
  Serial.println();
  
  // initialize the SD card at SPI_HALF_SPEED to avoid bus errors with
  // breadboards.  use SPI_FULL_SPEED for better performance.
  if (!card.init(SPI_HALF_SPEED)) error("card.init failed");
  
  // initialize a FAT volume
  if (!volume.init(&card)) error("volume.init failed");
  
  // open the root directory
  if (!root.openRoot(&volume)) error("openRoot failed");
  
  // open a file
  if (file.open(&root, “SENSOR.TXT", O_READ)) {
    Serial.println("Opened SENSOR.TXT");
  }

  else{
    error("file.open failed");
  }
  Serial.println();
  
  // copy file to serial port
  int16_t n;
  uint8_t buf[7];// nothing special about 7, just a lucky number.
  while ((n = file.read(buf, sizeof(buf))) > 0) {
    for (uint8_t i = 0; i < n; i++) 
    { 
      //Serial.print(buf[i]);
      responseArray[i] = buf[i];
      Serial.print("responseArray[");
      Serial.print(i);
      Serial.print("] = ");
      Serial.println(responseArray[i]);
    }
  }
  /* easier way
  int16_t c;
  while ((c = file.read()) > 0) Serial.print((char)c);
  */
  Serial.println("\nDone");
  
   char *p = sz;
   char *str;

//   while ((str = strtok_r(p, ",", &p)) != "\n") // delimiter is the semicolon
//   Serial.println(str);
  
}
void loop(void) {}

Here I have two examples combined into one program. Neither piece seems to be working yet, but I feel like I am close. When I run this, I am seeing this:

Opened MDCO.TXT

responseArray[] = 0
responseArray[] = .
responseArray[] = 0
responseArray[] = 0
responseArray[] = 

responseArray[] = 

responseArray[] = 0
responseArray[] = .
responseArray[] = 0
responseArray[] = 8
responseArray[] = 

responseArray[] = 

responseArray[] = -
responseArray[] = 0
responseArray[] = .
responseArray[] = 1
responseArray[] = 0
responseArray[] = 

responseArray[] =

I am FINALLY seeing the data coming in from the SD card, but I don’t seem to be able to put it into the array correctly. First, the i that I am using to increment the array element doesn’t seem to be working correctly. It doesn’t print, so I am assuming that I am putting the value from the TXT file into the same element. No?

Second, how the heck do I combine/append the values that are coming in into the correct format? Right now it looks like I am picking off each individual value and putting that into its own element. My values range from 0.00 to ?0.10 to 12.45 etc. To be honest, as these will be user generated, I can’t guarantee that they will be a known length. What if the user uses something like 12439.122. I would prefer if it wouldn’t break.

I don’t understand enough about bits and bytes and chars to know what the heck I am doing wrong. I understand that I am doing something with each individual character that I retrieve. How do I parse this? I have tried using a CSV format, but couldn’t figure out how to parse it correctly. That seems to be the most straightforward way of doing this. I would simply read from the SD card until I hit a comma, and then insert that value into the array element. No luck though.

This is why I tried using each number on a separate line like this:

(this is what SENSOR.TXT currently looks like)

0.00
0.08
-0.10
0.56
1.36
1.89
3.15
3.15
5.23
6.20
7.34
9.71
9.29
10.76
13.43
17.42
16.76

It seems like my code is even picking up the CR in the text file. Ack, I am a bit lost now. Anyone able to help guide me do something like a CSV parser using my code as a base? I was thrilled to get it this far...

...now I am stumped.

Thanks again for your help.

Ryan