题目为2.编写整理字符串的函数char*deleteChSet(char s1, chars2)删除字符串s1中所有在字符串s2中出现的字符。函数返回字符串s1。以下是我的代码
修改如下:
#include <stdio.h>
#include <string.h>
char* deleteChSet(char* s1, const char* s2) {
int i = 0, j;
char* p = s1;
while (*p != '\0') {
if (strchr(s2, *p) == NULL) {
s1[i++] = *p;
}
p++;
}
s1[i] = '\0';
return s1;
}
int main() {
char s1[100], s2[100];
printf("请输入s1字符串:");
fgets(s1, sizeof(s1), stdin);
s1[strcspn(s1, "\n")] = '\0';
printf("请输入s2字符串:");
fgets(s2, sizeof(s2), stdin);
s2[strcspn(s2, "\n")] = '\0';
printf("删除s1中含有s2的字符:%s\n", deleteChSet(s1, s2));
return 0;
}