Hello,
I'm wiriting a code to reading a first 100 numbers from a file and I need to save them to a string. Here is my code:
File dir = SD.open("file_name.csv", FILE_READ);
String values = "";
char val[3];
bool isEnd = false;
for(int i = 0; i < 100; i++) {
memset(val, 0 , 3);
for(int i = 0; i < 3; i++) {
if(!dir.available())
{
isEnd = true;
dir.close();
}
val = char(dir.read());
_ Serial.println(val*);_
_ }_
_ if(isEnd)_
_ {_
char tekst[] = "GET_VALUES ERR NO_MORE_VALUES\n";
FILE file = fopen("/tmp/ble_pipe_in", "w");
* size_t ch_count = fwrite(tekst, sizeof(char), strlen(tekst), file);
_ fclose(file);_
_ return false;_
_ }_
_ val[3] = '\0';_
_ Serial.println(val);_
_ if(!dir.available())_
_ {_
_ isEnd = true;_
char tekst[] = "GET_VALUES ERR NO_MORE_VALUES\n";
FILE file = fopen("/tmp/ble_pipe_in", "w");
* size_t ch_count = fwrite(tekst, sizeof(char), strlen(tekst), file);
_ fclose(file);_
_ return false;_
_ }_
_ dir.read();_
_ if(!dir.available())_
_ {_
_ isEnd = true;_
char tekst[] = "GET_VALUES ERR NO_MORE_VALUES\n";
FILE file = fopen("/tmp/ble_pipe_in", "w");
* size_t ch_count = fwrite(tekst, sizeof(char), strlen(tekst), file);
_ fclose(file);_
_ return false;_
_ }_
_ dir.read();_
_ //char num[4];_
_ //sprintf(num, "%d", myFile.read());_
_ Serial.println(values);_
_ values += val;_
_ //AppendString(val, values);_
_ //strcat(values, val);_
_ Serial.println(values);_
_ if(!dir.available())_
_ {_
_ isEnd = true;_
char tekst[] = "GET_VALUES ERR NO_MORE_VALUES\n";
FILE file = fopen("/tmp/ble_pipe_in", "w");
* size_t ch_count = fwrite(tekst, sizeof(char), strlen(tekst), file);
_ fclose(file);_
_ return false;_
_ }_
_ if(i != 99)_
_ values += ",";_
_ //AppendString(",", values);_
_ Serial.println(values);_
_ }*_