Teensy 4.1 SD edit .txt file on specific location

Thisara

New member
Hi
I'm tiring edit text file using seek function. But see always return 0. Here is the function I'm using

void SaveScount(int in, String Scount){
//Serial.println(Scount);

ScoFile = SD.open("SwitchCount5.txt",O_APPEND);
if(ScoFile){
Serial.println(in);
ScoFile.seek(in*31);
Serial.println(myFile.position());
//ScoFile.print(in);
//ScoFile.println(":");
ScoFile.println(Scount);

}
else{

Serial.println("file opning fails");
}
}
 
Pro tip: you can format your code by wrapping your code in “CODE” tags or by pressing the “</>” button in the editor. That will make the code in your questions easier to read.
 
C++:
void SaveScount(int in, String Scount){
//Serial.println(Scount);

ScoFile = SD.open("SwitchCount5.txt",O_APPEND);
if(ScoFile){
Serial.println(in);
ScoFile.seek(in*31);
Serial.println(myFile.position());
//ScoFile.print(in);
//ScoFile.println(":");
ScoFile.println(Scount);

}
else{

Serial.println("file opning fails");
}
}
 
Thanks shawn. I changed it.
I chuckled when I saw this. :)
One of the things that wrapping it in the code tag helps is the formatting. Lines can have indents too. Unless… did all your code between the braces line up with the first column?
 
Pro tip: you can format your code by wrapping your code in “CODE” tags or by pressing the “</>” button in the editor. That will make the code in your questions easier to read.
Next level (or lower?) tip: In IDE 1 or 2 [command may be different in other IDE] do:

Ctrl + T : 'Auto Format'

Copy & Pasting code after that assures some uniform formatting and indenting.

This Ctrl+T is also handy when unclear/Random Build Errors show up. If the Auto Format cannot properly (as expected) parse the code - then neither can the compiler.
> unbalanced PARENS or QUOTES or Missing Semi Colons, etc

Will then show when reading through the code bad/unexpected indenting at those points if they exist.
 
Back
Top