Countdown on SD Card (remaining minutes logger)

Hi all, I’ll start explaining the objective and I would love if someone could point the error(s) in the code because it is not working as intended.

I’m trying to put a file on an SD card (via pc), set a number of minutes on it (let’s say 10 minutes, but they could be 100000) and it has to decrease this number down to 0 (it has to “expire”).

I’ve managed to use TimeAlarms lib and it does do something every minute but only the first reading is correct.

The first reading is a direct string reading from the file (that’s why it is correct), but the second, and third and so on reading is always 49.

It doesn’t write to the file because if I insert the sd card on my computer it does still say 10.

Where does this 49 come from?

I’m pretty sure that there is a massive error, but I can’t figure it out, here’s the code:

#include <SPI.h>
#include <SD.h>
#include <Time.h>
#include <TimeAlarms.h>

File dataFile;

void setup()
{
  Serial.begin(9600);
  Serial.print("Initializing SD card...");
  if (!SD.begin(10))
  {
    Serial.println("Card failed, or not present");
    return;
  }
  Serial.println("card initialized.");
  setTime(8,29,0,1,1,11);
  Alarm.timerRepeat(60, Repeats);
  dataFile = SD.open("timeout.txt");
  if (dataFile)
  {
    Serial.print("available minutes: ");
 while (dataFile.available()) {
    Serial.write(dataFile.read());}
    dataFile.close();
  }
  else
  { 
    Serial.println("error");
  }
}
void loop()
{
   Alarm.delay(0);
}
void Repeats(){
    dataFile = SD.open("timeout.txt");
    char ch = dataFile.read()
    int NoF = 10 * (ch-'0');
    ch = dataFile.read();
    NoF = NoF + ch-'0';
    unsigned long values[NoF];
    dataFile.println(values[NoF] - 1);
    dataFile.close();
    dataFile = SD.open("timeout.txt");
    Serial.print("available minutes: ");
    Serial.println(dataFile.read());
    dataFile.close();
}

Thanks for anyone who will help me!

It doesn’t write to the file because if I insert the sd card on my computer it does still say 10.
Where does this 49 come from?

49 is the decimal representation of ASCII 1.

After several try i came out with this and it's working as intended:

void Repeats(){
    logFile = sd.open("TIMEOUT.LOG", O_READ);
    int g;
    g = logFile.parseInt();
    Serial.print(g);
    Serial.println(" MINUTES LEFT");
    logFile.close();
    logFile = sd.open("TIMEOUT.LOG", O_WRITE | O_TRUNC);
    int h = g-1;
    logFile.print(h);
    logFile.close();
}

I'm sure it can be optimized in order to be faster, but how?