Reputation: 1
I have this:
Serial.write(charBuf[0]); //gives 5
String data(charBuf);
Serial.write(data); //gives nothing (space)
first is prints 5 , second prints nothing. What am i missing? is it has to do with NULL terminated stuff?
This is how the buffer is being created:
int len=1;
char charBuf[len];
for(int k=ACT_THRESH;k<ACT_THRESH+len;k++)
{
charBuf[k-ACT_THRESH]= EEPROM.read(k);
}
Upvotes: 1
Views: 30
Reputation: 7622
int len = 1;
int str_len = 0;
char charBuf[16];
for(int k = ACT_THRESH; k < ACT_THRESH + len && str_len < sizeof(charBuf); k++)
{
charBuf[str_len++]= EEPROM.read(k);
}
charBuf[str_len] = '\0';
But I don't get the goal of the loop if len = 1
Upvotes: 1