I have been trying to convert numbers in lines of a txt file into usable integers. I have a file filled with numbers, and I have narrowed the problem down to the fact that the file isn't successfully being turned into an array.

So I just broke it down into trying to print the numbers one by one on a serial monitor (there are 500 lines in the text file, each containing characters that look like numbers)

Here is the code:

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

const int chipSelect = 4;
char array[500];
int n = 0;

void setup()
  Serial.print("Initializing SD Card....");
    Serial.println("Card failed, or not Present");
  Serial.println("Card Initialized");
  File dataFile = SD.open("list.txt");
     array[500] = dataFile.read();

    Serial.println("File does not exist");
  n = 0;
  while (n < 500) {
    n = n + 1;

void loop()


It returns:

Initializing SD Card....Card Initialized

and then 500 lines of blank text. I don't think I'm doing the array conversion right.

EDIT; One more thing I forgot, I can't really use a big text file, unless theres a way to only store one line in dynamic memory at a time. Is it possible to only check a single line of a text file?

  • Look into what sorts of read methods the File class provides. Ideally you can read a parsed number or a line. Certainly, you can read one of either bytes or sectors and parse that yourself. – Chris Stratton Jan 17 '15 at 21:14
  • Since you posted this same underlying problem again with subsequent detail of an attempted solution and got an answer which more fully explains it in reply, this is really an unnecessary duplicate now. – Chris Stratton Jan 18 '15 at 6:07
  • @ChrisStratton Well I had figured out how to print the text, then I was just trying to store it in integers, so I'd say not really the same... but you might be right. – user3151828 Jan 18 '15 at 13:13
  • What's wrong with your other question? They seem very similar... – Anonymous Penguin Jan 18 '15 at 14:56
  • @AnnonomusPenguin The other one I asked has more information (it was actually answered too). Also this one is asking about receiving no numbers on the monitor, but the other one is asking about receiving the wrong numbers. It is kinda the same, yeah. – user3151828 Jan 18 '15 at 15:16

Browse other questions tagged or ask your own question.