<?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 Re: Problem with sprintf and zero padding [CodeWarrior 6.1 for V1 core ] in CodeWarrior for QorIQ</title>
    <link>https://community.nxp.com/t5/CodeWarrior-for-QorIQ/Problem-with-sprintf-and-zero-padding-CodeWarrior-6-1-for-V1/m-p/172791#M2887</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi, copy the file &lt;STRONG&gt;printf_tiny_IO.c&lt;/STRONG&gt; located in the &amp;lt;Program Files\Freescale\CodeWarrior for Microcontrollers V6.1\ColdFire_Support\msl\MSL_C\MSL_Common\Src&amp;gt; into your project, modify it and then compile. You must ensure that this file is the first in the link order.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best regards !&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 28 Apr 2009 20:58:27 GMT</pubDate>
    <dc:creator>Richard777</dc:creator>
    <dc:date>2009-04-28T20:58:27Z</dc:date>
    <item>
      <title>Problem with sprintf and zero padding [CodeWarrior 6.1 for V1 core ]</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-QorIQ/Problem-with-sprintf-and-zero-padding-CodeWarrior-6-1-for-V1/m-p/172787#M2883</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi guys, I have problems with sprintf and zero padding, look this example:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;
...&amp;nbsp; char szTemp[80];&amp;nbsp; unsigned int Written;&amp;nbsp; Written = 1;&amp;nbsp; sprintf( szTemp, "%02u", Written&amp;nbsp; + 1 );...&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The result in szTemp array&amp;nbsp;is the following:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;szTemp[0] =&amp;nbsp;0x31;&lt;/P&gt;&lt;P&gt;&amp;nbsp;szTemp[1] =&amp;nbsp;0x00;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The zero padding does not seem to work, also I looked the source file &lt;STRONG&gt;printf_tiny_io.c&lt;/STRONG&gt; ( source file for printf/sprintf functions ) and I have found the problem.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;
/*** Line number 653 ****/&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* pad left */&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (width &amp;amp;&amp;amp; !(flags &amp;amp; _PRINTF_LEFT)) {&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (!(flags &amp;amp; _PRINTF_ZEROPAD)) {/* pad with spaces */&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; do {&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; out(' '); --width;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; } while (width);&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; } else {#if LIBDEF_PRINTF_PREC&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; prec += width; #endif&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; width = 0; /* pad with zeros */&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The left pad work only with space !. My corrections to these:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* pad left */&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (width &amp;amp;&amp;amp; !(flags &amp;amp; _PRINTF_LEFT)) {&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (!(flags &amp;amp; _PRINTF_ZEROPAD)) {/* pad with spaces */&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; do {&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; out(' '); --width;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; } while (width);&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; } else {#if LIBDEF_PRINTF_PREC&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; prec += width; #endif&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* pad with zeros */&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; do {&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; out('0'); --width;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; } while (width);&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/PRE&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;Sorry for my poor english and best regards !&lt;/P&gt;&lt;DIV class="message-edit-history"&gt;&lt;SPAN class="edit-author"&gt;Message Edited by Richard777 on&lt;/SPAN&gt; &lt;SPAN class="local-date"&gt;2009-04-16&lt;/SPAN&gt; &lt;SPAN class="local-time"&gt;05:24 PM&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 29 Oct 2020 09:21:19 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-QorIQ/Problem-with-sprintf-and-zero-padding-CodeWarrior-6-1-for-V1/m-p/172787#M2883</guid>
      <dc:creator>Richard777</dc:creator>
      <dc:date>2020-10-29T09:21:19Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with sprintf and zero padding [CodeWarrior 6.1 for V1 core ]</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-QorIQ/Problem-with-sprintf-and-zero-padding-CodeWarrior-6-1-for-V1/m-p/172788#M2884</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Richard,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The fix is fine if LIBDEF_PRINTF_PREC is set to 0, but if it is enabled (it is not for CF, it is for HC08/HC12) it causes the added zeros to be dublicated.&lt;/P&gt;&lt;P&gt;Here's a fixed version:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;
          /* pad left */          if (width &amp;amp;&amp;amp; !(flags &amp;amp; _PRINTF_LEFT)) {            if (!(flags &amp;amp; _PRINTF_ZEROPAD)) {/* pad with spaces */              do {                out(' '); --width;              } while (width);            } else {              /* pad with zeros */#if LIBDEF_PRINTF_PREC              prec += width;               width = 0;#else              do {                out('0'); --width;              } while (width);#endif            }          }&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As alternative for your fix, you could also set&amp;nbsp; LIBDEF_PRINTF_PREC to 1 for CF too.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Daniel&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 29 Oct 2020 09:21:21 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-QorIQ/Problem-with-sprintf-and-zero-padding-CodeWarrior-6-1-for-V1/m-p/172788#M2884</guid>
      <dc:creator>CompilerGuru</dc:creator>
      <dc:date>2020-10-29T09:21:21Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with sprintf and zero padding [CodeWarrior 6.1 for V1 core ]</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-QorIQ/Problem-with-sprintf-and-zero-padding-CodeWarrior-6-1-for-V1/m-p/172789#M2885</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Daniel, thanks for your responce. I think that the&amp;nbsp;first solution is better because the define &lt;STRONG&gt;LIBDEF_PRINT_PREC&lt;/STRONG&gt; refer to precision no to padding, look the following note in the CodeWarrior help:&amp;nbsp;&lt;FONT face="arial,helvetica,sans-serif" size="2"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Arial"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;FONT face="arial,helvetica,sans-serif" size="2"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;FONT face="arial,helvetica,sans-serif" size="2"&gt;&amp;nbsp;&lt;/FONT&gt; #define LIBDEF_PRINTF_PREC&amp;nbsp;&amp;nbsp;&amp;nbsp;(1 || LIBDEF_PRINTF_FLOATING) &amp;nbsp;&lt;P&gt;Set to 1 if '.' (precision support) in printf/scanf is needed.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&amp;nbsp;&lt;P&gt;Best regards !&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 17 Apr 2009 21:39:43 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-QorIQ/Problem-with-sprintf-and-zero-padding-CodeWarrior-6-1-for-V1/m-p/172789#M2885</guid>
      <dc:creator>Richard777</dc:creator>
      <dc:date>2009-04-17T21:39:43Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with sprintf and zero padding [CodeWarrior 6.1 for V1 core ]</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-QorIQ/Problem-with-sprintf-and-zero-padding-CodeWarrior-6-1-for-V1/m-p/172790#M2886</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks - have spent hours fighting this.&amp;nbsp; So, as a "don't fiddle with the libraries" type of user, I have changed the .c file - now how do I force the compiler to recompile and link the libraries?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried to load hc08_lib.mcp and compile it, but my compiler is limited to 32k and so it failed.&lt;/P&gt;&lt;DIV class="message-edit-history"&gt;&lt;SPAN class="edit-author"&gt;Message Edited by Hummingbird Electronics on&lt;/SPAN&gt; &lt;SPAN class="local-date"&gt;2009-04-28&lt;/SPAN&gt; &lt;SPAN class="local-time"&gt;11:13 AM&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 28 Apr 2009 17:09:44 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-QorIQ/Problem-with-sprintf-and-zero-padding-CodeWarrior-6-1-for-V1/m-p/172790#M2886</guid>
      <dc:creator>HummingbirdElec</dc:creator>
      <dc:date>2009-04-28T17:09:44Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with sprintf and zero padding [CodeWarrior 6.1 for V1 core ]</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-QorIQ/Problem-with-sprintf-and-zero-padding-CodeWarrior-6-1-for-V1/m-p/172791#M2887</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi, copy the file &lt;STRONG&gt;printf_tiny_IO.c&lt;/STRONG&gt; located in the &amp;lt;Program Files\Freescale\CodeWarrior for Microcontrollers V6.1\ColdFire_Support\msl\MSL_C\MSL_Common\Src&amp;gt; into your project, modify it and then compile. You must ensure that this file is the first in the link order.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best regards !&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 28 Apr 2009 20:58:27 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-QorIQ/Problem-with-sprintf-and-zero-padding-CodeWarrior-6-1-for-V1/m-p/172791#M2887</guid>
      <dc:creator>Richard777</dc:creator>
      <dc:date>2009-04-28T20:58:27Z</dc:date>
    </item>
  </channel>
</rss>

