I need help about \0 and readstringuntil, I cant make it work even if i make a custom readstringuntil
String readStringFast(char delimiter) {
String line = "";
while (true) {
char c = SerialBT.read();
if (c == delimiter) {
line += delimiter;
break;
} else {
line += c;
}
}
return line;
}
How are you entering the '\0' ?
1 Like
gcjr
3
look this over
String
readStringFast (char delimiter)
{
String line = "";
while (true) {
if (Serial.available ()) {
char c = Serial.read();
line += c;
if (c == delimiter)
return line;
}
}
}
// -----------------------------------------------------------------------------
void loop (void)
{
if (Serial.available ()) {
#if 1
Serial.print (readStringFast ('\n'));
#else
char buf [80];
int n = Serial.readBytesUntil ('\n', buf, sizeof(buf)-2);
buf [n] = '\n';
buf [n+1] = '\0';
Serial.print (buf);
#endif
}
}
void setup (void)
{
Serial.begin (9600);
}
system
Closed
5
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.