[I2C] Save received string

Hi,
I sending from "arduino 1" to "arduino 2" string (HI) and received like that:

void DaemonReceiving(int howMany){
  Serial.print("RECEIVED: ");

  while(Wire.available() > 0){
    char c = Wire.read();
    Serial.print(c);
  }
}

Ok, I see "RECEIVED: HI". So, now I want write HI to char* variable. When I make:

char dataRx[10] = "";

(...)

while(Wire.available() > 0){
    char c = Wire.read();
    strcat(dataRx, c);
  }

I get error "Invalid conversion from 'char' to 'const char*'. Where is the problem and how I can write received string to a variable?

Where is the problem

Where you try to use a character where a string is expected.

All that code happens in a loop. Create an index variable (int), initialized to 0. Every time you read a character, add it to the array, increment the index, and add a NULL.

  int index = 0;
  while(Wire.available() > 0){
    char c = Wire.read();
    Serial.print(c);
    dataRx[index++] = c;
    dataRx[index] = '\0';
  }

Yes, this is good reason :smiley: Thnx for your help! When it works I have another problem :slight_smile:

void DaemonReceiving(int howMany){
  int index = 0;

  while(Wire.available() > 0){
    char c = Wire.read();

    dataRx[index++] = c;
    dataRx[index] = '\0';
  }
  Serial.println(dataRx);

  if(strcmp(dataRx, "HELLO") == 0){
        Wire.beginTransmission(1);
        Wire.write("HI");
        Wire.endTransmission();
  }
}

When this condition is met, uC freezes on Wire.(...) commands :-/