Arduino SDFat Libray overwrites last value I'm trying to create a comma delimited file using this SDFat library
Calling this code creates my file
const char Header[24]=&quot;Desired RPM,Output RPM\n&quot;;
...
foo()
{
  SpeedCache.open(&quot;/Speed_Cache.txt&quot;,O_CREAT | O_RDWR | O_APPEND);
  SpeedCache.write(Header);
  SpeedCache.sync();
}
...

After running, I have a file containing

Desired RPM,Output RPM'\n'

When I call the following function, I want it to add int target and int reference to the bottom of the file.
bool SDClass::SetLine(SdFile Cache,int target, int reference)
{   
  bool good = false;
  char NewLine[32];
  Cache.seekEnd();
  sprintf_P(NewLine,(PGM_P)F(&quot;%d,%d\n&quot;),target,reference);
  Serial.println(good=Cache.write(NewLine));
  Cache.sync();
  return good;
}

On the first call, this works so for an input of SpeedCache,50,100 I get

Desired RPM,Output RPM'\n'
50,100'\n'

However, if I then write an input of SpeedCache,5,10 I get

Desired RPM,Output RPM'\n'
5,10'\n'

How do I adjust my function so that I will get:

Desired RPM,Output RPM'\n'
50,100'\n'
5,10'\n'
You just need to open the file in APPEND mode:

SpeedCache.open("/Speed_Cache.txt",O_CREAT | O_RDWR | O_APPEND);



  O_APPEND
  
  The  file  is  opened  in append mode.  Before each write, the file offset is positioned at the end of  the  file,  as  if  with               lseek.


You should also pass your file around by reference so it doesn't keep creating new copies of the internal structure:

bool SDClass::SetLine(SdFile &amp;Cache,int target, int reference)