<?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>Classic/Legacy CodeWarrior中的主题 Re: Sprintf error - Codewarrior 8.1.1a</title>
    <link>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/Sprintf-error-Codewarrior-8-1-1a/m-p/207880#M5797</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for the help.&amp;nbsp; I found bigmac's solution to be the best.&amp;nbsp; I had one of those "duh" moments when he reminded me that 115200 is to big for an unsigned integer.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I already recieve the baud rate in as an ASCII string via the serial port so I have simply dropped the '0' off the end then I do an atoi() and this solved the problem.&amp;nbsp; When I report the data back out the suggested "SB%u00\r" is perefect.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks again.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 25 Jun 2010 05:04:40 GMT</pubDate>
    <dc:creator>v_dave</dc:creator>
    <dc:date>2010-06-25T05:04:40Z</dc:date>
    <item>
      <title>Sprintf error - Codewarrior 8.1.1a</title>
      <link>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/Sprintf-error-Codewarrior-8-1-1a/m-p/207876#M5793</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a bit of a strange one here and I just can't seem to find a solution.&amp;nbsp; I use sprintf() to format strings which I then send out a SCI port a little later.&amp;nbsp; My problem is one particular string that I build has an incorrect number in it after sprintf() is complete.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;typedef struct MOT_PARAM{...unsigned int BaudRate;&amp;nbsp; //Baudrate setting between Main and Interface PCB...}mot_param;mot_param UA_Param;unsigned char debug_buf[64];size = sprintf((char *)debug_buf, "SB%d\r", (unsigned)UA_Param.BaudRate);&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So here is the issue:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if UA_Param.BaudRate = 4800 or 9600 or 19200 then he string created is always correct i.e.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;SB4800\r&lt;/P&gt;&lt;P&gt;SB9600\r&lt;/P&gt;&lt;P&gt;SB19200\r&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However when UA_Param.BaudRate is greater than 19200 (such as 38400, 57600 &amp;amp; 115200) then the output string has the negative value of the Baudrate i.e.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So if UA_Param.BaudRate = 38400 i get SB-27136\r but it should be SB38400\r&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I cannot figure out is why any number larger than 19200 is being converted incorrectly.&amp;nbsp; Does anyone have any ideas?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Details:&lt;/P&gt;&lt;P&gt;Target CPU - DSC56F8323&lt;/P&gt;&lt;P&gt;Codewarrior 8.1.1a for the DSC56F8000E&lt;/P&gt;&lt;P&gt;My Desktop OS - Win XP SP3&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance for any help.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 18 Jun 2010 05:32:38 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/Sprintf-error-Codewarrior-8-1-1a/m-p/207876#M5793</guid>
      <dc:creator>v_dave</dc:creator>
      <dc:date>2010-06-18T05:32:38Z</dc:date>
    </item>
    <item>
      <title>Re: Sprintf error - Codewarrior 8.1.1a</title>
      <link>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/Sprintf-error-Codewarrior-8-1-1a/m-p/207877#M5794</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Printf conversion type character 'd' is for signed integers. 'u' - for unsigned. You should change %d to %u.&lt;/P&gt;&lt;P&gt;Printf has no way to check&amp;nbsp;what you are pushing to the stack in parameter list. Printf uses format string as a declaration what are you passing to it.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 18 Jun 2010 11:13:54 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/Sprintf-error-Codewarrior-8-1-1a/m-p/207877#M5794</guid>
      <dc:creator>kef</dc:creator>
      <dc:date>2010-06-18T11:13:54Z</dc:date>
    </item>
    <item>
      <title>Re: Sprintf error - Codewarrior 8.1.1a</title>
      <link>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/Sprintf-error-Codewarrior-8-1-1a/m-p/207878#M5795</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Additionally,&amp;nbsp;a value of 115200 would exceed the bounds of an unsigned int, and would require a long integer to handle.&amp;nbsp; Another approach would be to handle the value as 96, 192, 384 .. 1152, and add the final two zeros as ASCII characters.&lt;/P&gt;&lt;P&gt;Maybe&amp;nbsp; &lt;FONT face="courier new,courier"&gt;"SB%u00\r",&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Mac&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 18 Jun 2010 13:31:06 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/Sprintf-error-Codewarrior-8-1-1a/m-p/207878#M5795</guid>
      <dc:creator>bigmac</dc:creator>
      <dc:date>2010-06-18T13:31:06Z</dc:date>
    </item>
    <item>
      <title>Re: Sprintf error - Codewarrior 8.1.1a</title>
      <link>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/Sprintf-error-Codewarrior-8-1-1a/m-p/207879#M5796</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Or simply save the baudrates as strings &amp;nbsp;&lt;IMG alt=":smileyhappy:" class="emoticon emoticon-smileyhappy" id="smileyhappy" src="http://freescale.i.lithium.com/i/smilies/16x16_smiley-happy.gif" title="Smiley Happy" /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It will mean an immense saving of flash memory. Am I nuts? No... because if they were saved as strings in the first place, you wouldn't need the horrible sprintf() function, nor would you need your own less horrible int-to-string function. &lt;IMG alt=":smileyhappy:" class="emoticon emoticon-smileyhappy" id="smileyhappy" src="http://freescale.i.lithium.com/i/smilies/16x16_smiley-happy.gif" title="Smiley Happy" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 22 Jun 2010 19:02:23 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/Sprintf-error-Codewarrior-8-1-1a/m-p/207879#M5796</guid>
      <dc:creator>Lundin</dc:creator>
      <dc:date>2010-06-22T19:02:23Z</dc:date>
    </item>
    <item>
      <title>Re: Sprintf error - Codewarrior 8.1.1a</title>
      <link>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/Sprintf-error-Codewarrior-8-1-1a/m-p/207880#M5797</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for the help.&amp;nbsp; I found bigmac's solution to be the best.&amp;nbsp; I had one of those "duh" moments when he reminded me that 115200 is to big for an unsigned integer.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I already recieve the baud rate in as an ASCII string via the serial port so I have simply dropped the '0' off the end then I do an atoi() and this solved the problem.&amp;nbsp; When I report the data back out the suggested "SB%u00\r" is perefect.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks again.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 25 Jun 2010 05:04:40 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/Sprintf-error-Codewarrior-8-1-1a/m-p/207880#M5797</guid>
      <dc:creator>v_dave</dc:creator>
      <dc:date>2010-06-25T05:04:40Z</dc:date>
    </item>
  </channel>
</rss>

