+= operator and Concat issues

Discussion in 'Arduino IDE' started by Ryan, Apr 14, 2014.

  1. Ryan

    Ryan New Member

    Joined:
    Dec 3, 2013
    Messages:
    8
    Likes Received:
    0
    There seems to be somewhat of an issue when i'm trying to add a char to a string. When this code uploads, nothing shows, but when using the Slave Receiver example, it reads what I want but without combining them together.

    My code is below.

    Code:
    while(Wire.available())    
      { 
        char c = Wire.read();    
        result += c;  //adds the read character to string to build full reading info. E.g. "2-20"
        
      }
      Serial.println(result); //prints result which is in turn picked up by control panel software
      result = ""; //reset string
    Any help would be greatly appreciated

    Ryan
     
  2. mkopack

    mkopack Member

    Joined:
    Jun 14, 2013
    Messages:
    451
    Likes Received:
    21
    Don't have access to my Udoo or arduino right now, but try this:

    Try casting the char to a string and using Concat:

    result.concat((String) c);

    That way you're appending a string to a string, rather than a char to a string.


    What sort of result are you seeing with the code you posted?
     
  3. Ryan

    Ryan New Member

    Joined:
    Dec 3, 2013
    Messages:
    8
    Likes Received:
    0
    Thanks for your reply.

    I tried using the += and concat functions, and nothing at all would show, and if i attempted to modify the sketch, to just add a print statement, nothing at all would show. It essentially broke the sketch. I'll get it tested on my udoo tomorrow morning.

    Thanks!

    P.S I wrote the code on an Uno originally, and worked perfectly.
     

Share This Page