user31567: I am having a bit of trouble loading values stored on an SD card and assigning them to variables within my program. I can achieve this as one big block of data, but would much prefer them to be saved to variables whilst in a loop or some other process.
My txt file has the following 6 ints & floats values, which are displayed vertically in the file:
2
0.003200
312
1
0.720000
8
Each of these values I want assigned to variables data1,....2,3,4,5,6. Unfortunately, the code I use below will never achieve this, but I am clueless as to any theory to solve this problem. Thanks in advance.
myFile = SD.open("test.txt", FILE_READ);
    if (myFile) {
    while (myFile.available()) {
        data = myFile.read();
    }
myFile.close();
}
else {
    Serial.println("Read Error");
}


user37622: File implements Stream just like Serial. so you can use parseInt and parseFloat 
int n = File.parseInt();
float x = File.parseFloat();
Serial.println(n);
Serial.println(x, 6);


31567: <p>I am having a bit of trouble loading values stored on an SD card and assigning them to variables within my program. I can achieve this as one big block of data, but would much prefer them to be saved to variables whilst in a loop or some other process.</p>

<p>My txt file has the following 6 ints &amp; floats values, which are displayed vertically in the file:</p>

<p>2
0.003200
312
1
0.720000
8</p>

<p>Each of these values I want assigned to variables data1,....2,3,4,5,6. Unfortunately, the code I use below will never achieve this, but I am clueless as to any theory to solve this problem. Thanks in advance.</p>

<pre><code>myFile = SD.open("test.txt", FILE_READ);
    if (myFile) {
    while (myFile.available()) {
        data = myFile.read();
    }
myFile.close();
}
else {
    Serial.println("Read Error");
}
</code></pre>
 37622: <p>File implements <a href="http://arduino.cc/reference/en/language/functions/communication/stream" rel="nofollow noreferrer">Stream</a> just like Serial. so you can use parseInt and parseFloat </p>

<pre><code>int n = File.parseInt();
float x = File.parseFloat();
Serial.println(n);
Serial.println(x, 6);
</code></pre>
