<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic [HC08 - CW6] How to append a uint8_t to a string in Classic/Legacy CodeWarrior</title>
    <link>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/HC08-CW6-How-to-append-a-uint8-t-to-a-string/m-p/163573#M2889</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi all.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I need to build a string appending a uint8_t. I tried with:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;DIV class="msg_source_code"&gt;&lt;DIV class="text_smallest"&gt;Code:&lt;/DIV&gt;&lt;PRE&gt;void sendLQI(uint8_t linkQuality) {&amp;nbsp;&amp;nbsp; char msg[30] = "Link quality: ";&amp;nbsp;&amp;nbsp; (void)strcat(msg,(char *)linkQuality);&amp;nbsp;&amp;nbsp; (void)Uart2_Transmit(msg,30,NULL);}&lt;/PRE&gt;&lt;/DIV&gt;&lt;BR /&gt;&amp;nbsp;But it doesn't seem to work. Any suggestion?&lt;BR /&gt;&lt;/DIV&gt;&lt;BR /&gt;&lt;DIV&gt; &lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 29 Oct 2020 09:09:56 GMT</pubDate>
    <dc:creator>CecchiSandrone</dc:creator>
    <dc:date>2020-10-29T09:09:56Z</dc:date>
    <item>
      <title>[HC08 - CW6] How to append a uint8_t to a string</title>
      <link>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/HC08-CW6-How-to-append-a-uint8-t-to-a-string/m-p/163573#M2889</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi all.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I need to build a string appending a uint8_t. I tried with:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;DIV class="msg_source_code"&gt;&lt;DIV class="text_smallest"&gt;Code:&lt;/DIV&gt;&lt;PRE&gt;void sendLQI(uint8_t linkQuality) {&amp;nbsp;&amp;nbsp; char msg[30] = "Link quality: ";&amp;nbsp;&amp;nbsp; (void)strcat(msg,(char *)linkQuality);&amp;nbsp;&amp;nbsp; (void)Uart2_Transmit(msg,30,NULL);}&lt;/PRE&gt;&lt;/DIV&gt;&lt;BR /&gt;&amp;nbsp;But it doesn't seem to work. Any suggestion?&lt;BR /&gt;&lt;/DIV&gt;&lt;BR /&gt;&lt;DIV&gt; &lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 29 Oct 2020 09:09:56 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/HC08-CW6-How-to-append-a-uint8-t-to-a-string/m-p/163573#M2889</guid>
      <dc:creator>CecchiSandrone</dc:creator>
      <dc:date>2020-10-29T09:09:56Z</dc:date>
    </item>
    <item>
      <title>Re: [HC08 - CW6] How to append a uint8_t to a string</title>
      <link>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/HC08-CW6-How-to-append-a-uint8-t-to-a-string/m-p/163574#M2890</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;You can't convert a number to text like that in C; the (char *) cast only claims to the compiler that the following identifier actually contains a pointer to a character (string). You must use an explicite function like sprintf or itoa (don't know if itoa exists in CW) to convert the number to a string.&lt;/DIV&gt;&lt;DIV&gt;Sten&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 13 Nov 2007 21:59:05 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/HC08-CW6-How-to-append-a-uint8-t-to-a-string/m-p/163574#M2890</guid>
      <dc:creator>Sten</dc:creator>
      <dc:date>2007-11-13T21:59:05Z</dc:date>
    </item>
    <item>
      <title>Re: [HC08 - CW6] How to append a uint8_t to a string</title>
      <link>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/HC08-CW6-How-to-append-a-uint8-t-to-a-string/m-p/163575#M2891</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;Which type of data is represented by uint8_t? Isn't it a char?&lt;BR /&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 13 Nov 2007 22:39:44 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/HC08-CW6-How-to-append-a-uint8-t-to-a-string/m-p/163575#M2891</guid>
      <dc:creator>CecchiSandrone</dc:creator>
      <dc:date>2007-11-13T22:39:44Z</dc:date>
    </item>
    <item>
      <title>Re: [HC08 - CW6] How to append a uint8_t to a string</title>
      <link>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/HC08-CW6-How-to-append-a-uint8-t-to-a-string/m-p/163576#M2892</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;I use the following functions to build text string with integer. Use Digits to set number of digits for number and decimal to set number of decimal places in converted number. Use decimal = 0 to leave decimal point out.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Lets say you use an integer to store the value 1000 and you want to represent as "10.00" in text string. You would then use Digits = 5 and Decimal = 2 when calling the function.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;/* Call function like this */&lt;/DIV&gt;&lt;DIV&gt;char Msg[30];&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;ItoaMsg(&amp;amp;Msg[0],&amp;nbsp;"Link Qaulity = ",&amp;nbsp;30,&amp;nbsp;2,&amp;nbsp;0);&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;Msg will contain the text message "Link Quality = 30" and will be NULL terminated ready to use.&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;Hope this helps&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;DIV class="msg_source_code"&gt;&lt;DIV class="text_smallest"&gt;Code:&lt;/DIV&gt;&lt;PRE&gt;/* Integer to ASCII */void Itoa(int Number, char Digits, char Decimal, char *String){ /* Get starting position in string array */ char *PositionSave, *Position = String + Digits;  /* Negative flag */ char NegativeFlag = FALSE; /* Charactor buffer */ char Chr; /* Working UINT16 */ unsigned int uInteger; /* Loop index */ int Index; /* Number of digits converted */ int DigitCount = 0;  /* Make sure we are converting more than one digit */ if(!Digits)  return;  /* Are we working with a negative number— */ if (Number &amp;lt; 0) {  /* It is a negative number */  NegativeFlag = TRUE;  /* Remove the sign bit from the integer */  uInteger = ((unsigned int)(-(1 + Number))) + 1; } else {  /* Not a negative number */  uInteger = Number; }  /* NULL terminate the string */ *Position = 0;  /* Do the conversion */ do {  /* Decrement the digits counter */  Digits--;  /* Get the ASCII charactor */  *--Position = '0' + (uInteger % 10);  /* Divide by 10 */  uInteger /= 10;  /* Have we reached the end of the number– */  if(!uInteger)   break;  /* Increment the digit counter */  DigitCount++;   } while (Digits);  /* Do we need to add a decimal point˜ */ if(Decimal &amp;amp;&amp;amp; Digits) {  /* Remove another digit position */  Digits--;    /* Do we have enough space for a leading 0™ */  if(Digits &amp;amp;&amp;amp; (DigitCount &amp;lt; Decimal)){   for(Index = Decimal - DigitCount; Index &amp;gt; 0; Index--) {    *--Position = '0';    DigitCount++;    Digits--;    if(!Digits)     break;   }  }    /* Decrement and save the pointer */  Position--;  PositionSave = Position;      /* Move the charactors */  for(Index = DigitCount - Decimal; Index &amp;gt;= 0; Index--) {   Chr = Position[1];   Position[0] = Chr;   Position++;  }  /* Insert the decimal point */  *Position = '.';  /* Restore the pointer */  Position = PositionSave; }    /* Do we need to add the negative sign? */ if (NegativeFlag &amp;amp;&amp;amp; Digits) {  /* Add the negative charator */  *--Position = '-';  /* Reduce the digit count */  Digits--; }  /* Do we need to pad any charactor positions? */ for(Index = Digits; Index != 0; Index--)   *--Position = ' ';}/* ItoaMsg */void ItoaMsg(char *Buffer, char *Msg, int Number, char Digits, char Decimal) { /* Local variables */ char Array[11];  /* Convert Number to string */ Itoa(Number, Digits, Decimal, &amp;amp;Array[0]);  /* Copy Msg to Buffer */ (void) strcpy(Buffer, Msg);  /* Add Number string to Buffer */ (void) strcat(Buffer, &amp;amp;Array[0]);}&lt;/PRE&gt;&lt;/DIV&gt;&lt;BR /&gt;&amp;nbsp;&lt;BR /&gt;&lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;Message Edited by Technoman64 on &lt;SPAN class="date_text"&gt;2007-11-14&lt;/SPAN&gt; &lt;SPAN class="time_text"&gt;02:20 AM&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 29 Oct 2020 09:09:58 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/HC08-CW6-How-to-append-a-uint8-t-to-a-string/m-p/163576#M2892</guid>
      <dc:creator>Technoman64</dc:creator>
      <dc:date>2020-10-29T09:09:58Z</dc:date>
    </item>
    <item>
      <title>Re: [HC08 - CW6] How to append a uint8_t to a string</title>
      <link>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/HC08-CW6-How-to-append-a-uint8-t-to-a-string/m-p/163577#M2893</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;Thanks for help &lt;A href="http://forums.freescale.com/../view_profile?user.id=722" rel="nofollow noopener noreferrer noopener noreferrer" target="top"&gt;&lt;SPAN&gt;Technoman64&lt;/SPAN&gt;&lt;/A&gt; I will try your function soon. However, I don't understand why in the debugger I can see 2 rows relative to the variable linkQuality as you can see in the image. In fact I took linkQuality directly from the original structure and its size was uint8_t. So when I try this code:&lt;BR /&gt;&lt;DIV&gt;&lt;DIV class="msg_source_code"&gt;&lt;DIV class="text_smallest"&gt;Code:&lt;/DIV&gt;&lt;PRE&gt;char msg[20] = "Link quality: ";
char value[6];
(void)sprintf(value,"%c",linkQuality);
(void)strcat(msg,value);
(void)Uart2_Transmit(msg,70,NULL);&lt;/PRE&gt;&lt;/DIV&gt;&lt;BR /&gt;&amp;nbsp;The msg string contains "Link quality: F" instead of "Link quality: 240". I tried also with %d in sprintf, with no success. Maybe do I wrong sprintf call?&lt;BR /&gt;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;A href="http://www.freescale.com/files/community_files/CWCOMM/msg5428_sshot_11.jpg" rel="nofollow noopener noreferrer noopener noreferrer" target="_self"&gt;sshot_11.jpg&lt;/A&gt;&lt;DIV class="message-edit-history"&gt;&lt;SPAN class="edit-author"&gt;Message Edited by t.dowe on&lt;/SPAN&gt; &lt;SPAN class="local-date"&gt;2009-09-04&lt;/SPAN&gt; &lt;SPAN class="local-time"&gt;11:04 AM&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 29 Oct 2020 09:09:59 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/HC08-CW6-How-to-append-a-uint8-t-to-a-string/m-p/163577#M2893</guid>
      <dc:creator>CecchiSandrone</dc:creator>
      <dc:date>2020-10-29T09:09:59Z</dc:date>
    </item>
    <item>
      <title>Re: [HC08 - CW6] How to append a uint8_t to a string</title>
      <link>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/HC08-CW6-How-to-append-a-uint8-t-to-a-string/m-p/163578#M2894</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;What result did you get when you tried the %d instead of %c? The %d should be the right choice if you want the number as decimal, if you want it in hexadecimal, use %x instead:&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;sprintf(msg, "Link quality: %x\n", linkQuality)&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Sten&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 15 Nov 2007 14:30:07 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/HC08-CW6-How-to-append-a-uint8-t-to-a-string/m-p/163578#M2894</guid>
      <dc:creator>Sten</dc:creator>
      <dc:date>2007-11-15T14:30:07Z</dc:date>
    </item>
    <item>
      <title>Re: [HC08 - CW6] How to append a uint8_t to a string</title>
      <link>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/HC08-CW6-How-to-append-a-uint8-t-to-a-string/m-p/163579#M2895</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;I tried also with sprintf(msg, "Link quality: %d\n", linkQuality) but I see incorrect values. &lt;SPAN&gt;&lt;IMG alt=":smileymad:" class="emoticon emoticon-smileymad" id="smileymad" src="http://freescale.i.lithium.com/i/smilies/16x16_smiley-mad.gif" title="Smiley Mad" /&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 15 Nov 2007 18:19:02 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/HC08-CW6-How-to-append-a-uint8-t-to-a-string/m-p/163579#M2895</guid>
      <dc:creator>CecchiSandrone</dc:creator>
      <dc:date>2007-11-15T18:19:02Z</dc:date>
    </item>
    <item>
      <title>Re: [HC08 - CW6] How to append a uint8_t to a string</title>
      <link>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/HC08-CW6-How-to-append-a-uint8-t-to-a-string/m-p/163580#M2896</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;/DIV&gt;sprintf is an advanced function as it provides no type checking, and for a small chip like a HC08 it is also&lt;BR /&gt;rather large resource wise.&lt;BR /&gt;The usual suspects if it does not work:&lt;BR /&gt;- missing include, no #include &amp;lt;stdio.h&amp;gt;&lt;BR /&gt;- not enough stack space.&lt;BR /&gt;- type of format string does not match with type actually passed.&lt;BR /&gt;&lt;BR /&gt;I would suggest to use a an explicit int -&amp;gt; string conversion function as the &lt;A href="http://forums.freescale.com/../view_profile?user.id=722" rel="nofollow" target="_blank"&gt;&lt;SPAN&gt;Technoman64&lt;/SPAN&gt;&lt;/A&gt; provided, it&lt;BR /&gt;fixes most of the issues of sprintf.&lt;BR /&gt;&lt;BR /&gt;Daniel&lt;BR /&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 15 Nov 2007 19:23:02 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/HC08-CW6-How-to-append-a-uint8-t-to-a-string/m-p/163580#M2896</guid>
      <dc:creator>CompilerGuru</dc:creator>
      <dc:date>2007-11-15T19:23:02Z</dc:date>
    </item>
    <item>
      <title>Re: [HC08 - CW6] How to append a uint8_t to a string</title>
      <link>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/HC08-CW6-How-to-append-a-uint8-t-to-a-string/m-p/163581#M2897</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;Yes with Technoman64's function my code works. Thanks&lt;BR /&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 15 Nov 2007 20:08:09 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/HC08-CW6-How-to-append-a-uint8-t-to-a-string/m-p/163581#M2897</guid>
      <dc:creator>CecchiSandrone</dc:creator>
      <dc:date>2007-11-15T20:08:09Z</dc:date>
    </item>
  </channel>
</rss>

