<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<atom:link href="https://www.gentoo-zh.org/extern.php?action=feed&amp;tid=341&amp;type=rss" rel="self" type="application/rss+xml" />
		<title><![CDATA[Gentoo中文社区 / C 练习实例32]]></title>
		<link>https://www.gentoo-zh.org/viewtopic.php?id=341</link>
		<description><![CDATA[C 练习实例32 最近发表的帖子。]]></description>
		<lastBuildDate>Mon, 29 Aug 2022 07:14:00 +0000</lastBuildDate>
		<generator>FluxBB</generator>
		<item>
			<title><![CDATA[C 练习实例32]]></title>
			<link>https://www.gentoo-zh.org/viewtopic.php?pid=347#p347</link>
			<description><![CDATA[<p>题目：删除一个字符串中的指定字母，如：字符串 &quot;aca&quot;，删除其中的 a 字母。</p><p>程序分析：无。 </p><div class="codebox"><pre class="vscroll"><code>#include&lt;stdio.h&gt;
#include&lt;stdlib.h&gt;
#include&lt;string.h&gt;
 
// 删除字符串中指定字母函数
char* deleteCharacters(char * str, char * charSet)
{
    int hash [256];
    if(NULL == charSet)
        return str;
    for(int i = 0; i &lt; 256; i++)
        hash[i] = 0;
    for(int i = 0; i &lt; strlen(charSet); i++)
        hash[charSet[i]] = 1;
    int currentIndex = 0;
    for(int i = 0; i &lt; strlen(str); i++)
    {
        if(!hash[str[i]])
            str[currentIndex++] = str[i];
    }
    str[currentIndex] = &#039;\0&#039;;
    return str;
}
 
int main()
{
    char s[2] = &quot;a&quot;;     // 要删除的字母
    char s2[5] = &quot;aca&quot;;  // 目标字符串
    printf(&quot;%s\n&quot;, deleteCharacters(s2, s));
    return 0;
}</code></pre></div>]]></description>
			<author><![CDATA[dummy@example.com (batsom)]]></author>
			<pubDate>Mon, 29 Aug 2022 07:14:00 +0000</pubDate>
			<guid>https://www.gentoo-zh.org/viewtopic.php?pid=347#p347</guid>
		</item>
	</channel>
</rss>
