1
0
mirror of https://github.com/2martens/uni.git synced 2026-05-06 11:26:25 +02:00

[ES] Added readString method

Signed-óff-by: Jim Martens <github@2martens.de>
This commit is contained in:
2015-07-04 12:29:57 +02:00
parent 1364ac3d9a
commit cf36412e51

View File

@ -1,4 +1,5 @@
#include <SPI.h> #include <SPI.h>
#include <SD.h>
// pins // pins
int slaveSelectPin = 10; int slaveSelectPin = 10;
@ -304,3 +305,35 @@ int printString(int x, int y, const char* text, int textLength)
return 0; return 0;
} }
/**
* Reads the contents of a text file into a string.
*
* Returns an empty string on failure.
*
* @param File file
*/
const char* readString(File file)
{
if (file) {
unsigned long fileSize = file.size();
char result[fileSize];
int i = 0;
while (file.available()) {
char c = file.read();
if (c != '\n') {
result[i] = c;
i++;
}
else {
result[i] = '\0';
}
}
return result;
}
else {
// something happened
return "";
}
}