<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[向东博客 专注WEB应用 构架之美 --- 构架之美，在于尽态极妍 | 应用之美，在于药到病除]]></title> 
<link>http://www.jackxiang.com/index.php</link> 
<description><![CDATA[赢在IT，Playin' with IT,Focus on Killer Application,Marketing Meets Technology.]]></description> 
<language>zh-cn</language> 
<copyright><![CDATA[向东博客 专注WEB应用 构架之美 --- 构架之美，在于尽态极妍 | 应用之美，在于药到病除]]></copyright>
<item>
<link>http://www.jackxiang.com/post//</link>
<title><![CDATA[[c++]snprintf学习,连接字符串可snprintf格式化，少可memcpy。]]></title> 
<author>jack &lt;xdy108@126.com&gt;</author>
<category><![CDATA[WEB2.0]]></category>
<pubDate>Wed, 10 Nov 2010 08:09:23 +0000</pubDate> 
<guid>http://www.jackxiang.com/post//</guid> 
<description>
<![CDATA[ 
	vi snprintf.cpp&nbsp;&nbsp;<br/><div class="code"> #include &lt;stdio.h&gt;<br/> int main()<br/> &#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp; char szValue&#91;1024&#93;;<br/>&nbsp;&nbsp;&nbsp;&nbsp; char snValue&#91;1024&#93;=&quot;jackxiang&#039;s test by ddd...&#92;n&quot;;<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp; snprintf(szValue,sizeof(szValue),&quot;printf add char =%s&quot;,snValue);<br/>&nbsp;&nbsp;&nbsp;&nbsp; printf(&quot;%s&quot;,szValue);<br/><br/><br/>&#125;</div><br/><br/>./a.out <br/>printf add char =jackxiang&#039;s test by ddd...<br/><br/><br/>Add Time :&nbsp;&nbsp;2014-02-10<br/>snprintf(szValue, sizeof(szValue), %4d%2d%2d&quot;,1900+p-&gt;tm_year,1+p-&gt;tm_mon,p-&gt;tm_mday);<br/>保证sizeof(szValue)大于9,只要一个sizeof就行。<br/>snprintf(szValue,1024,&quot;%s%s%s&quot;,Y,M,D);<br/><br/>连接字符串可snprintf格式化，少可memcpy:<br/><textarea name="code" class="php" rows="15" cols="100">
char contentRangeStr[1024]=&quot;X-Content-Range: bytes &quot;; //contentRange字符串
u64 rangeBegin;//range开起值
u64 rangeEnd;//range开起值
snprintf(contentRangeStr,sizeof(contentRangeStr),&quot;%s%d-%d/%d&quot;,contentRangeStr,rangeBegin,rangeEnd,filesize);////X-Content-Range: bytes 10737418230-10737418239/10737418240
</textarea><br/>我是64位整数，需要ld格式化？是我这样写？<br/>%ld，输出长整型数据。例：long a=135790；printf（“%ld”，a）；如果用%d输出就会发生错误，因为整型数据的范围是-32768到32767.对long型数据应当用%ld格式输出，对长整型数据也可以指定字段宽度，如：%8ld。<br/>————————————————————————————————————————————————————————————————————————<br/><br/>函数原型：<br/>int snprintf(char *str, size_t size, const char *format, ...);<br/><br/>size代表长度，如果要拷贝到szValue的数据长度超过size，就会被截断。<br/>这样保证拷贝的数据缓冲区不溢出<br/><br/>
]]>
</description>
</item><item>
<link>http://www.jackxiang.com/post//#blogcomment</link>
<title><![CDATA[[评论] [c++]snprintf学习,连接字符串可snprintf格式化，少可memcpy。]]></title> 
<author> &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Thu, 01 Jan 1970 00:00:00 +0000</pubDate> 
<guid>http://www.jackxiang.com/post//#blogcomment</guid> 
<description>
<![CDATA[ 
	
]]>
</description>
</item>
</channel>
</rss>