Converting char to string

Hi,

I made a piece of software that allows me to send a message from a pc to an Arduino via an XBee Pro, but im having some trouble getting my original message back.
On my pc, i insert a string (a , b , c ) that i turn into HEX (the xbee library needs that), gets sent, and on the receiving side i print every character with:

for (int i= rx.getDataOffset(); i < xbee.getResponse().getFrameDataLength(); i++){

        if (iscntrl(xbee.getResponse().getFrameData()[i]))
        {
        }
        else
        {
          Serial.write(xbee.getResponse().getFrameData()[i]);
        }
      }

which works flawless, since it prints a , b , c on my screen.
However, if i try to turn this into a string for further handling, i can’t get it to work.
for example:

char c[50];
      for (int i= rx.getDataOffset(); i < xbee.getResponse().getFrameDataLength(); i++){
        if (iscntrl(xbee.getResponse().getFrameData()[i]))
        {
          Serial.write(" ");
        }
        else
        {
          Serial.write(xbee.getResponse().getFrameData()[i]);
          c[i - rx.getDataOffset()] = char(xbee.getResponse().getFrameData()[i]);
        }
      }
      Serial.println("");
      Serial.println(c);

will return a,cb

Can anyone point me in the right direction?

A number of things, you should try help people to help you:

First of all, dont post snippets, post the whole code or include it if it is to large.
Secondly format your code so that it is readble:

for (int i= rx.getDataOffset(); i < xbee.getResponse().getFrameDataLength(); i++){

        if (iscntrl(xbee.getResponse().getFrameData()[i]))
        {
        }
        else
        {
          Serial.write(xbee.getResponse().getFrameData()[i]);
        }
      }

Should be:

for (int i= rx.getDataOffset(); i < xbee.getResponse().getFrameDataLength(); i++){
  if (iscntrl(xbee.getResponse().getFrameData()[i]));
  else {
    Serial.write(xbee.getResponse().getFrameData()[i]);
  }//if-else
}//for(int i)

Thirdly the logic makes little sense. Its much easier written as:

for (int i= rx.getDataOffset(); i < xbee.getResponse().getFrameDataLength(); i++)
  if (!iscntrl(xbee.getResponse().getFrameData()[i]))
    Serial.write(xbee.getResponse().getFrameData()[i]);

Fourthly a string is a character array terminated with a ‘\0’ (null character). I’m not sure that you are inserting this character at the and of the string.

I'm not sure that you are inserting this character at the and of the string.

OP isn't, and that IS the problem.