Right then. Problem solved I think
My txt file has 16 numbered rows. Starting with #1. #2. #3 etc.
The next 12 letters after that describe what that line should contain.
Then there are up to 30 characters of data.
My code looks through the file, finds a hash and prints the line number and description (but does not store them). Then stores the following >30 characters in EEPROM.
Each EEPROM start position is derived from the line number.
If it encounters the hash of the next line before the full 30 characters, it grabs that read position, knocks it back one place and allows the routine to continue.
The step back of one place then allows it to find the hash again that it just used as the end of the previous data line.
void setup()
{
Serial.begin(9600); // Open serial communications and wait for port to open:
while (!Serial) {
}
Serial.print(F("Checking for SD card... "));
Serial.println();
if (SD.begin(4)) {
Serial.println(F("Found SD card"));
delay(50);
// Open the file for reading:
myFile = SD.open("SiteData.txt");
if (myFile) {
Serial.println(F("SiteData.txt:"));
Serial.println(F(" "));
// read from the file until there's nothing else in it:
while (myFile.available()) {
hash1=myFile.read(); //Search for a hash
if (hash1==35) { //If a hash is found, get the line number of the data
Serial.print(char(hash1)); //Display the hash+line number
data1=(myFile.read()-48);
data2=(myFile.read()-48);
data3=((data1*10)+data2); //Calculate which line number we are reading
Serial.print(data3);
EEPROM.write((data3*30)-30,data3); //Store the line number at its own line number address *30 then -30 (because there is no zero line number)
for (count=0;count<=12;count++) { //Skip the next 12 spaces/letters as they are the reference text. Just print them to the serial monitor
Serial.print(char(myFile.read()));
}
for (count=0;count<=30;count++) { //Read the next 30 letters or numbers and store them incrementally from the known line number start point
readposition=(myFile.position()); //Get the current read position
data1=(myFile.read());
if (data1==35) { //If it finds another hash at the beginning of the next line, then process ready for next line data
myFile.seek(readposition-1); //Move the read position back one byte
break; //Exit this line read
}
Serial.print(char(data1));
EEPROM.write(((data3*30)-30)+count,data1);
}
if (count==30) {Serial.print('\n');} //If it doesn't move to the next line due to finding the next hash, then force a new line
if (data3>=16) {break;} //If all 16 files are found, then exit
}
}
// close the file:
myFile.close();
} else {
// if the file didn't open, print an error:
Serial.println(F("error opening SiteData.txt"));
}
}else {Serial.print(F("No SD card present, using memory stored data"));}