I am reading sd card .txt file, I want to read the first line then how to save the position of the pointer for the next line read?
2 Answers
You should not need to save the position, the file knows where you last read from. You'd only need to manually save such information if you close the file and re-open it again, which unless you have a good reason is actually a very wasteful operation.
If you really do need to you can use the .position()
and .seek()
functions:
Save the location:
uint32_t pos = myFile.position();
Recall the location:
myFile.seek(pos);
Documentation:
File myFile = SD.open("test.txt", O_RDWR);
if (myFile) {
while (myFile.available()) {
int i = 0;
while (i < myFile.size()) {
inputString = myFile.readStringUntil('\n');
//Serial.print(inputString);
if (myFile.readStringUntil('\n')) {
I have set a size for the loop, every time it returns "I want it to read a new line" but it skips, what could be the reason?
To help with this question, I wanted to show the process I did on the same question. Thank you, I will ask the question elsewhere. I am sending from the serial port when the end of the line is not read twice, during each reading. I'm sending line by line
-
Please ask questions as new questions rather than in an answer on another different question. After deleting this, when you create your new question, please be as specific and clear as possible (and maybe explain why you're doing two
readStringUntil
s in a row). Commented Jun 21, 2021 at 17:31 -
evet dediğinizi anladım ve kaldırdım. Çok teşekkür ederim. işe yarıyor. cevabımı bir yere yazmak gerekirse bana bildiriniz ben oraya cevap olarak eklemek isterim.– ismallCommented Jun 21, 2021 at 19:15
-