AnsweredAssumed Answered

STM32F4, Could I extend a string with sensor value?

Question asked by tang.ho_tin on Mar 25, 2015
Latest reply on Mar 26, 2015 by tang.ho_tin
Thank for your look and help.

I want to send a string "#1250#", and the 1250 is the sensor value.
So I do some try.
            uint16_t ch=1250;
          uint16_t Value[4];
          char str[10] = "#";
            Value[0] = (ch /1000 )+48 ; // divide number by 1000
            ch = (ch % 1000) ; // take remainder number of 1000
            Value[1] = (ch / 100 )+48; // divide this now by 100
            ch = (ch % 100 )  ;// take remainder of 100
            Value[2] = (ch / 10)+48 ;  // divide remainder by 10
            Value[3] = (ch % 10 ) +48; // load remainder of final Dimension into unit variable
          strcat(str,Value);
          strcat(str,"#");
However, when I look at debug mode, it give me the result
str[0]='#'
str[1]='1'
str[2]='2'
str[3]='5'
str[4]='0'
str[5]=2
str[6]='#'
there is a non need 2 appear in str[5]

but when I change   strcat(str,Value) to  strcat(str,"1250")
there are no matter.

May I ask what is the problem of doing this?

Outcomes