I have following function for my Arduino:
String readLine() {
String received = "";
char ch;
while (myFile.available()) {
ch = myFile.read();
if (ch == '\n' or ch == '\r') {
if (ch == '\r')
{
//get rid of the \n
myFile.read();
}
return String(received);
} else {
received += ch;
}
}
myFile.close();
hasFile = false;
return received;
}
This function is used to return a line from a text file on a SD card. Since I do have to do quite some things on the returned string, I would like to have it as cstr instead of string to increase performance. But I am not able to convert this function to one that returns a Cstr. I tried this but it does not work:
char* readLine() {
char* received = "";
char ch;
while (myFile.available()) {
ch = myFile.read();
if (ch == '\n' or ch == '\r') {
if (ch == '\r')
{
//get rid of the \n
myFile.read();
}
return received;
} else {
received += ch;
}
}
return received;
}
Currently I am converting it after the function returns it, by using c_str()
. It works, but I dont like it and would like to return a Cstr in the first place.
How can this be done?
Thank you!