How to read lines from SD and store them into array with unknown size

I'm working on small project and need to read each line from txt file and store it into array, but lines vary from time to time, array must be type long...
I came to this point, but I've no clue how to use dynamic array size
CODE:

#include <SPI.h>
#include <SD.h>
long tags[24];
String buffer;
File dataFile;
void setup() {
  Serial.begin(9600);
  while (!Serial) {}
  Serial.print("Initializing SD card...");
  if (!SD.begin(4)) {
    Serial.println("initialization failed!");
    while (1);
  }
  Serial.println("initialization done.");
  dataFile = SD.open("tags.txt");
  delay(1000);
  if (dataFile) {
    Serial.println("tags.txt:");
    int n = 0;
    while (dataFile.available()) {
      buffer = dataFile.readStringUntil('\n');
      tags[n] = buffer.toInt();
      n++;
    }
    dataFile.close();
  }
  else {
    Serial.println("error opening tags.txt");
  }
}
void loop() {
  Serial.println("Printing result");
  int numOfTags = (sizeof(tags) / sizeof(tags[0]));
  for (int i = 0; i < numOfTags; i++) {
    Serial.println(tags[i]);
    delay(10);
  }
  Serial.println("End result");
  delay(50000);
}

Content of file is:

5922805
7028992
1812691
1870427
1852396
and so on

Which Arduino are you using?
These microprocessors have relatively little memory so dynamically allocating memory from the heap can quite easily cause the heap to become fragmented. There is also no garbage collection, this means you will need to manage the ram yourself. Is there a maximum number of records, if so could you dimension the array at that size?

Is this part of a large project because as shown you could do without using an array at all, just printing out the nubers as you have read them.

I'm using arduino mega... The idea is to load rfid tags stored on SD card (in setup, at boot up) and then compare readed tags to elements in this array
Tags won't be more then 250 e.g. lines

Since the Mega has 256K sram and 256 RFID nos at 4bytes each would only require 1K I believe you would be better off ignoring the use of dynamic memory and simply using a 256 element array of longs.

Another way to do this is to have files with names that are the numbers you want to look up. When the RFID card is read, you can look for the presence of the file. If is exists you have a match.

marco_c:
Another way to do this is to have files with names that are the numbers you want to look up. When the RFID card is read, you can look for the presence of the file. If is exists you have a match.

My concern with this approach is it will be unnecessary delay reading each time sd card... also I would like to take off sd card and update it on PC while board is running, then put it back, reboot the board and voila.
I'll stick to fixed array size -> long tags[250]; hope it works fine