﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>C++博客-浮生如梦-随笔分类-C</title><link>http://www.cppblog.com/masiyou/category/12019.html</link><description>沉思往事立残阳，当时只道是寻常</description><language>zh-cn</language><lastBuildDate>Thu, 08 Oct 2009 06:15:39 GMT</lastBuildDate><pubDate>Thu, 08 Oct 2009 06:15:39 GMT</pubDate><ttl>60</ttl><item><title>关于strtok函数</title><link>http://www.cppblog.com/masiyou/archive/2009/10/07/98038.html</link><dc:creator>浮生如梦</dc:creator><author>浮生如梦</author><pubDate>Wed, 07 Oct 2009 11:14:00 GMT</pubDate><guid>http://www.cppblog.com/masiyou/archive/2009/10/07/98038.html</guid><wfw:comment>http://www.cppblog.com/masiyou/comments/98038.html</wfw:comment><comments>http://www.cppblog.com/masiyou/archive/2009/10/07/98038.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/masiyou/comments/commentRss/98038.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/masiyou/services/trackbacks/98038.html</trackback:ping><description><![CDATA[<p>#include &lt;string.h&gt;<br>#include &lt;stdio.h&gt;</p>
<p>int main(void)<br>{<br>&nbsp;&nbsp; char input[16] = "abc,dhh,eee";<br>&nbsp;&nbsp; char *p;</p>
<p>&nbsp;&nbsp; /* strtok places a NULL terminator<br>&nbsp;&nbsp; in front of the token, if found */<br>&nbsp;&nbsp; p = strtok(input, ",");<br>&nbsp;&nbsp; if (p)&nbsp;&nbsp; printf("%s\n", p);</p>
<p>&nbsp;&nbsp; /* A second call to strtok using a NULL<br>&nbsp;&nbsp; as the first parameter returns a pointer<br>&nbsp;&nbsp; to the character following the token&nbsp; */<br>&nbsp;&nbsp; p = strtok(NULL, ",");<br>&nbsp;&nbsp; if (p)&nbsp;&nbsp; printf("%s\n", p);</p>
<p>&nbsp;&nbsp; p = strtok(NULL, ",");<br>&nbsp;&nbsp; if (p)&nbsp;&nbsp; printf("%s\n", p);<br>&nbsp;&nbsp; return 0;<br>}<br><br><span id=comment_body_365528>MSDN上的原话： <br>On the first call to strtok, the function skips leading delimiters and returns a pointer to the first token in strToken, terminating the token with a null character. More tokens can be broken out of the remainder of strToken by a series of calls to strtok. Each call to strtok modifies strToken by inserting a null character after the token returned by that call. To read the next token from strToken, call strtok with a NULL value for the strToken argument. The NULL strToken argument causes strtok to search for the next token in the modified strToken. The strDelimit argument can take any value from one call to the next so that the set of delimiters may vary. <br><br>第二次参数竟然可以NULL<br>是因为strtok中用static指针记住了上次处理后的位置<br><br>我想是因为这个函数内部实现时，用到了静态变量，而要不要修改这个变量，就是要根据第一个参数来确定！ <br><br>当为NULL时，就不再修改Static变量的值了！ <br><br>这个静态变量的作用，就是记录原始字符串的长度的！ <br></span></p>
<img src ="http://www.cppblog.com/masiyou/aggbug/98038.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/masiyou/" target="_blank">浮生如梦</a> 2009-10-07 19:14 <a href="http://www.cppblog.com/masiyou/archive/2009/10/07/98038.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>枚举与对应项字符串的转化</title><link>http://www.cppblog.com/masiyou/archive/2009/10/07/98025.html</link><dc:creator>浮生如梦</dc:creator><author>浮生如梦</author><pubDate>Wed, 07 Oct 2009 07:10:00 GMT</pubDate><guid>http://www.cppblog.com/masiyou/archive/2009/10/07/98025.html</guid><wfw:comment>http://www.cppblog.com/masiyou/comments/98025.html</wfw:comment><comments>http://www.cppblog.com/masiyou/archive/2009/10/07/98025.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/masiyou/comments/commentRss/98025.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/masiyou/services/trackbacks/98025.html</trackback:ping><description><![CDATA[<p>#include &lt;iostream&gt;</p>
<p>using namespace std;</p>
<p>enum language{java, c, pascal, fortran, vc, vb, cpp} lang;</p>
<p>char name[][10] = {<br>"java",<br>"c",<br>"pascal",<br>"fortran",<br>"vc",<br>"vb",<br>"cpp"<br>};</p>
<p>int main()<br>{<br>&nbsp;&nbsp;&nbsp; lang = fortran;<br>&nbsp;&nbsp;&nbsp; cout &lt;&lt; name[lang] &lt;&lt; endl;</p>
<p>&nbsp;&nbsp;&nbsp; lang = java;<br>&nbsp;&nbsp;&nbsp; cout &lt;&lt; name[lang] &lt;&lt; endl;</p>
<p>&nbsp;&nbsp;&nbsp; lang = pascal;<br>&nbsp;&nbsp;&nbsp; cout &lt;&lt; name[lang] &lt;&lt; endl;</p>
<p>&nbsp;&nbsp;&nbsp; lang = (language) 6;//这个强转经典<br>&nbsp;&nbsp;&nbsp; cout &lt;&lt; name[lang] &lt;&lt; endl;<br>&nbsp;&nbsp;&nbsp; return 0;<br>}<br></p>
<img src ="http://www.cppblog.com/masiyou/aggbug/98025.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/masiyou/" target="_blank">浮生如梦</a> 2009-10-07 15:10 <a href="http://www.cppblog.com/masiyou/archive/2009/10/07/98025.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>