/* 自学C语言第一个自己写的小程序,起因是把书上题看错了……*/
#include <stdio.h>
int strlen(char s[]);
void squeeze(char s1[], char s2[]);
main(){
char s1[] = "i am your father, father's fatheer.";
char s2[] = "father";
squeeze(s1, s2);
for (int i = 0; s1[i] != '\0'; ++i)
putchar(s1[i]);
system("pause");
return 0;
}
void squeeze(char s1[], char s2[]) {
int i, j, u;
j = u = 0;
int l = strlen(s2);
for (i = 0; s1[i] != '\0'; i++) {
if (s1[i] != s2[u]) {
if (u != 0) {
for (int x = 0; x <= u; ++x) {
s1[j] = s1[i - u + x];
++j;
}
u = 0;
}
else
s1[j++] = s1[i];
}
else {
if (u < (l-1))
++u;
else
u = 0;
}
}
s1[j] = '\0';
}
int strlen(char s[]) {
int i;
for (i = 0; s[i] != '\0'; i++)
;
return i;
}
在字符串S1中去除所有字符串S2
最新推荐文章于 2023-01-05 16:49:28 发布