C 练习实例32 2021年12月6日 20:17:242021年12月7日C语言教程评论1,059 雨后池塘,个人日记空间!点击进入» C 练习实例32 题目:删除一个字符串中的指定字母,如:字符串 "aca",删除其中的 a 字母。 程序分析:无。 实例 #include<stdio.h> #include<stdlib.h> #include<string.h> // 删除字符串中指定字母函数 char* deleteCharacters(char * str, char * charSet) { int hash [256]; if(NULL == charSet) return str; for(int i = 0; i < 256; i++) hash[i] = 0; for(int i = 0; i < strlen(charSet); i++) hash[charSet[i]] = 1; int currentIndex = 0; for(int i = 0; i < strlen(str); i++) { if(!hash[str[i]]) str[currentIndex++] = str[i]; } str[currentIndex] = '\0'; return str; } int main() { char s[2] = "a"; // 要删除的字母 char s2[5] = "aca"; // 目标字符串 printf("%s\n", deleteCharacters(s2, s)); return 0; } 以上实例输出结果为: c 历年同日文章 12 月6 2024家庭用电度数、电费在线计算工具 点赞 登录收藏 https://www.gongshiku.com/html/202112/c-lianxishili32.html 复制链接 复制链接 运营不易, 感谢支持! 我的微信 微信号已复制 我的微信公众号 我的微信公众号扫一扫 我的公众号 公众号已复制