Txt read third line

Hi ı want to read specific line from txt file.Here is my code.This code read all lines.What is wrong here? Thank you for your effort and knowledge.
#include <SPI.h>
#include <SdFat.h>

#define DIRECTORY_ENTRY_LENGTH 30
#define FILE_LINE_LENGTH 30

SdFat SD; //Main SD Object
int count=0;
int id=3;
void setup() {
Serial.begin(9600);

if(!SD.begin(4)){
Serial.println(" Error initializing SD Card ");
return;
}

readFile("/","NAMES.txt");
}

void loop() {
/* NOTHING */
}

void readFile(char* Path, char* FileName){
Serial.print(F(" -- Reading entries from file = "));
Serial.print(Path);
Serial.println(FileName);
SdFile directory;
SdFile file;

if(SD.chdir(Path)){
if(file.open(FileName)){

char Line[FILE_LINE_LENGTH];
memset(Line,0,sizeof(Line));
char Char[2];
memset(Char,0,sizeof(Char));

while (file.available()) {
Char[0] = file.read();
if(Char[0]=='\n'){
count=count+1;
if(count==id);{
Serial.println(Line);
}
memset(Line,0,sizeof(Line));
}
else if(Char[0]>=32)
strcat(Line,Char);
}
file.close();
}
else
Serial.println(F("ERROR: Couldn't open file."));

directory.close();
}
else
Serial.println(F("ERROR: Couldn't open path."));

Serial.println(F("DONE Reading"));
}

//if(count==id);{
if(count==id){
Serial.println(Line);

Remove the ; after the conditional.

1 Like

Hahaha ı feel like i'm blind. Thank you so much :slight_smile:

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.