SD reading question

Hello

I have a bunch of numbers each on a new line in a file on a SD card. I want to read the numbers as integers. When I used this following code I am able to print out all the values to the terminal.

  while (myFile.available()) {
      Serial.write(myFile.read());
      delay(100);
    }
    myFile.close();

When I try using the following code to actually extract the data in a variable it doesnt work. The values printed to terminal are incorrect.

  while (myFile.available()) {
     temp = myFile.read(); // declared earlier
     Serial.println(temp);
      delay(100);
    }
    myFile.close();

What am I doing wrong? Is there a problem with data type conversions? Thanks

How is temp declared ? Please post your whole program in order to make providing help easier.

This is how temp is coded.

int temp;

What type of variable is returned by

myFile.read();

Please give an example of what you expect and what you actually get. Can you see a relationship between them and post your whole program !

In your first code, you are reading and printing CHARACTERS. You need to store the characters in a character array, until you encounter a line feed or carriage return, keeping the array NULL terminated after each addition.

Then, you can use atoi() to convert the array to an int.