#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 s2[81];
printf("请输入目标字符串:\n",s2);
scanf("%s",&s2); // 目标字符串
char deletes[81];
printf("请输入要删除的字母:\n",deletes);
scanf("%s",&deletes); // 要删除的字母
printf("删除后得到的字符串为:\n%s", deleteCharacters(s2, deletes));
return 0;
}
#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 s2[81];
printf("请输入目标字符串:\n",s2);
scanf("%s",&s2); // 目标字符串
char deletes[81];
printf("请输入要删除的字母:\n",deletes);
scanf("%s",&deletes); // 要删除的字母
printf("删除后得到的字符串为:\n%s", deleteCharacters(s2, deletes));
return 0;
}