<?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 question</title>
    <link>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/sprintf-question/m-p/164772#M2956</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Note that the difference in between %c and %d is not the size of the printed output, its the formatting used.&lt;/P&gt;&lt;P&gt;With a printf("%d", '0') the ASCII code of the '0; character is printed, "48".&lt;/P&gt;&lt;P&gt;With a printf("%c", '0') the character '0' is literally, say as string "0"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Note that there is no way to pass a character (or short) to function with a open parameter declaration like printf (and sprintf), using"%d" for a character argument is the correct way if you want to print the numerical value.&lt;/P&gt;&lt;P&gt;I personally try to avoid printfw style functions because of the lack of argument type checking, but I know they are convenient and sometimes the best thing available. When using them I always explicitly cast the argument to the expected type to make sure the types match also when later on some variable types get changed elsewhere.&lt;/P&gt;&lt;P&gt;E.g. char c = 12; printf("%d", (int)c);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Daniel&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 05 Jan 2010 23:11:26 GMT</pubDate>
    <dc:creator>CompilerGuru</dc:creator>
    <dc:date>2010-01-05T23:11:26Z</dc:date>
    <item>
      <title>sprintf question</title>
      <link>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/sprintf-question/m-p/164769#M2953</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;hi all!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am use codewarrior for microcontroller special edition V6.2 and for coldire v7.1.AND find one question about sprintf function. It seem not support "%C" format arguments. I write the code:&lt;/P&gt;&lt;P&gt;uint8 c;&amp;nbsp;&lt;/P&gt;&lt;P&gt;sprintf(buf,"char you send is:%c\N",c);&amp;nbsp;&lt;/P&gt;&lt;P&gt;uart_putstr( buf);&lt;/P&gt;&lt;P&gt;I got "char you send is: &amp;nbsp; "&lt;/P&gt;&lt;P&gt;but if I change"%c"to"%d",I got correct ascii code of the c.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 04 Jan 2010 17:53:17 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/sprintf-question/m-p/164769#M2953</guid>
      <dc:creator>bluehacker</dc:creator>
      <dc:date>2010-01-04T17:53:17Z</dc:date>
    </item>
    <item>
      <title>Re: sprintf question</title>
      <link>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/sprintf-question/m-p/164770#M2954</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;The C language is case-sensitive.&lt;BR /&gt;&lt;BR /&gt;%C gives a year, according to the C standard, as opposed to %c which prints a character.&lt;BR /&gt;\N is not a valid escape sequence in the C language. I believe using one that isn't valid is undefined behavior.&lt;BR /&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 04 Jan 2010 19:52:29 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/sprintf-question/m-p/164770#M2954</guid>
      <dc:creator>Lundin</dc:creator>
      <dc:date>2010-01-04T19:52:29Z</dc:date>
    </item>
    <item>
      <title>Re: sprintf question</title>
      <link>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/sprintf-question/m-p/164771#M2955</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;thanks!&lt;/P&gt;&lt;P&gt;I press wrong character here. the code is use %c and \n not %C and\N&lt;/P&gt;&lt;P&gt;it still don't work&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 05 Jan 2010 18:54:52 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/sprintf-question/m-p/164771#M2955</guid>
      <dc:creator>bluehacker</dc:creator>
      <dc:date>2010-01-05T18:54:52Z</dc:date>
    </item>
    <item>
      <title>Re: sprintf question</title>
      <link>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/sprintf-question/m-p/164772#M2956</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Note that the difference in between %c and %d is not the size of the printed output, its the formatting used.&lt;/P&gt;&lt;P&gt;With a printf("%d", '0') the ASCII code of the '0; character is printed, "48".&lt;/P&gt;&lt;P&gt;With a printf("%c", '0') the character '0' is literally, say as string "0"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Note that there is no way to pass a character (or short) to function with a open parameter declaration like printf (and sprintf), using"%d" for a character argument is the correct way if you want to print the numerical value.&lt;/P&gt;&lt;P&gt;I personally try to avoid printfw style functions because of the lack of argument type checking, but I know they are convenient and sometimes the best thing available. When using them I always explicitly cast the argument to the expected type to make sure the types match also when later on some variable types get changed elsewhere.&lt;/P&gt;&lt;P&gt;E.g. char c = 12; printf("%d", (int)c);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Daniel&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 05 Jan 2010 23:11:26 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/sprintf-question/m-p/164772#M2956</guid>
      <dc:creator>CompilerGuru</dc:creator>
      <dc:date>2010-01-05T23:11:26Z</dc:date>
    </item>
    <item>
      <title>Re: sprintf question</title>
      <link>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/sprintf-question/m-p/164773#M2957</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I know the difference between %c and %d. BUT the following code don't work:&lt;/P&gt;&lt;P&gt;uint8 &amp;nbsp;c=48;&lt;/P&gt;&lt;P&gt;sprintf(buf,"%c",c);&lt;/P&gt;&lt;P&gt;uart_putstr(buf);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if I change to &amp;nbsp;sprintf(buf,"%d",c);&lt;/P&gt;&lt;P&gt;I got correct '48' in hyperterminal of microsoft windows&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 07 Jan 2010 13:58:08 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/sprintf-question/m-p/164773#M2957</guid>
      <dc:creator>bluehacker</dc:creator>
      <dc:date>2010-01-07T13:58:08Z</dc:date>
    </item>
    <item>
      <title>Re: sprintf question</title>
      <link>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/sprintf-question/m-p/164774#M2958</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;What do you get with the %c? And what do you expect to receive?&lt;/P&gt;&lt;P&gt;I would expect to get a "0" for %c.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Daniel&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 07 Jan 2010 22:57:31 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/sprintf-question/m-p/164774#M2958</guid>
      <dc:creator>CompilerGuru</dc:creator>
      <dc:date>2010-01-07T22:57:31Z</dc:date>
    </item>
    <item>
      <title>Re: sprintf question</title>
      <link>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/sprintf-question/m-p/164775#M2959</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I just test again, my code is:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;char ch=0;&lt;/P&gt;&lt;P&gt;char buf[50];&lt;/P&gt;&lt;P&gt;ch='a';&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;sprintf(buf,"%c",ch);&amp;nbsp;&lt;/P&gt;&lt;P&gt;uart_putstr(0,buf);&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;//the uart_putstr function code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/********************************************************************/&lt;/P&gt;&lt;P&gt;/*&lt;/P&gt;&lt;P&gt;&amp;nbsp;* Wait for space in the UART Tx FIFO and then send a character&lt;/P&gt;&lt;P&gt;&amp;nbsp;*/&amp;nbsp;&lt;/P&gt;&lt;P&gt;void uart_putchar (uint8 channel, char ch)&lt;/P&gt;&lt;P&gt;{&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;/* Wait until space is available in the FIFO */&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;while (!(MCF_UART_USR(channel) &amp;amp; MCF_UART_USR_TXRDY))&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;{&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &lt;SPAN class="Apple-tab-span"&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;};&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;/* Send the character */&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;MCF_UART_UTB(channel) = (uint8)ch;&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/*********************&lt;/P&gt;&lt;P&gt;* send a string using poll mode&lt;/P&gt;&lt;P&gt;*******************/&lt;/P&gt;&lt;P&gt;void uart_putstr(uint8 channel, char *str)&lt;/P&gt;&lt;P&gt;{&lt;/P&gt;&lt;P&gt;while(*str!=0)&lt;/P&gt;&lt;P&gt;{&lt;/P&gt;&lt;P&gt;uart_putchar(channel,*str++);&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I expect to get 'a' display in hyperterminal. but in fact , I get nothing, hyperterminal don't recieve anything.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;but &amp;nbsp;if i change to &amp;nbsp;sprintf(buf,"%d",ch); I get correct '97' in hyperternimal.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 08 Jan 2010 11:17:16 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/sprintf-question/m-p/164775#M2959</guid>
      <dc:creator>bluehacker</dc:creator>
      <dc:date>2010-01-08T11:17:16Z</dc:date>
    </item>
    <item>
      <title>Re: sprintf question</title>
      <link>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/sprintf-question/m-p/164776#M2960</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;I did perform some tests on CodeWarior for MCU V6.2.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In fact in order to be able to print characters in a sprintf or printf call&amp;nbsp; you need to rebuild your MSL library with&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; #define LIBDEF_PRINTF_CHAR&amp;nbsp; 1&lt;/P&gt;&lt;P&gt;in C/C++ Preprocessor panel.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Open the project {Install}\ColdFire_Support\msl\MSL_C\MSL_ColdFire\Project\MSL_C.CF.v1.mcp&amp;nbsp; in CodeWarrior&lt;/P&gt;&lt;P&gt;Check which library you are linking with your application.&lt;/P&gt;&lt;P&gt;Select the Corresponding Build target&lt;/P&gt;&lt;P&gt;Add the following to the C/C++ Preprocessor panel&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; #define LIBDEF_PRINTF_CHAR&amp;nbsp; 1&lt;/P&gt;&lt;P&gt;rebuild the library&lt;/P&gt;&lt;P&gt;rebuild the project.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;There might be something similar on V7.x.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;CrasyCat&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 13 Jan 2010 08:13:24 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/sprintf-question/m-p/164776#M2960</guid>
      <dc:creator>CrasyCat</dc:creator>
      <dc:date>2010-01-13T08:13:24Z</dc:date>
    </item>
  </channel>
</rss>

