2

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?

1
  • You mean like using a variable to save the number of the current line? What have you tried so far? Please show the code, that you already have
    – chrisl
    Commented Apr 12, 2021 at 20:45

2 Answers 2

3

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:

1

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

3
  • 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 readStringUntils 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.
    – ismall
    Commented Jun 21, 2021 at 19:15
  • Answering your own questions is perfectly fine :) Commented Jun 21, 2021 at 19:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.