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?

  • 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
    Apr 12 '21 at 20:45

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:




File myFile = SD.open("test.txt", O_RDWR);

if (myFile) {
  while (myFile.available()) {
    int i = 0;
    while (i < myFile.size()) { 
      inputString =  myFile.readStringUntil('\n');      
      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 readStringUntils in a row). Jun 21 '21 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.
    – is_mail
    Jun 21 '21 at 19:15
  • Answering your own questions is perfectly fine :) Jun 21 '21 at 19:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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