给定字符串“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;}输出结果:
新闻热点
疑难解答