首页 > 学院 > 开发设计 > 正文

删除字符串中指定的一些字符

2019-11-06 07:10:38
字体:
来源:转载
供稿:网友

给定字符串“the c PRogramming language ”,删除字符串中和“aeum”中字符相同的字符:

char * delChs(char * strScr, char * strDel){ if (strScr == NULL || strDel == NULL) { return NULL; } int flag[MAX_LEN] = {0}; while (*strDel != '/0') { flag[*strDel] = 1; ++strDel; } char * temp1 = strScr; char * temp2 = strScr; while (*temp2 != '/0') { if (!flag[*temp2]) { *temp1 = *temp2; ++temp1; } ++temp2; } *temp1 = '/0'; return strScr;}

验证程序:

int main(){ char * str = "the c programming language"; char * del = "aeum"; char * temp = new char[strlen(str) + 1]; strcpy_s(temp, strlen(str) + 1, str); printf("%s/n", delChs(temp, del)); delete [] temp; temp = NULL; return 0;}

输出结果: 这里写图片描述


上一篇:实验1:2

下一篇:js中 arguments 对象

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表