I have mega2560 but I think maybe my problem is still memory oriented.
Since others in forum has advised me NOT to use String …
So this was my first try to use buffer instead of String as return from my SDread function.
I was thinking this might help since it can be relative big.
But maybe it’s more inportant to get rid of the number of String items, even if relative small … ?
Probably I have to learn more on how to use buffers and get rid of the String stuff
Your buf4 is global, so SDread does not have to take a pointer (localcp) to a buffer as a parameter; you can directly manipulate buf4 in SDread.
If you want to pass the pointer (localcp) because you want to keep it flexible and might (in future) want to pass different buffers, you can directly manipulate localcp.
In both cases, there is no need for buff3.
You can start getting rid of String by replacing things like the below
Serial.println("numoflf " + String(m));
by
Serial.print("numoflf "); Serial.println(m);
You can make your code far easier to understand if you use decent variable names. E.g.
1)
The variable m in SDread counts number of lines; so call it something like numOfLines.
2)
buf2[25] seems to be an array with offset in the file that contain the beginning of a line; if so, why do you call it buf2 and not something like offsetTable.