编写函数squeeze(s1,s2),将字符串s1中任何与字符串s2中匹配的字符都删除
C语言,编写函数squeeze(s1,s2),将字符串s1中任何与字符串s2中匹配的字符都删除程序如下,书上的题目,我先自己做了一遍感觉循环那出了问题,改了好多遍都没成功,自己百度搜索相关题目,感觉不是一种写法,对比之后还是检查不出来(水平有限,感觉我逻辑很差{:10_266:} ),请大佬们帮帮忙,看看程序问题出现在哪里。感激感激{:10_254:}{:10_254:}
#include <stdio.h>
void squeeze(char s1[], char s2[]);
int main()
{
char s1[] = {'a','b','c','d','e','f','g','h','i','k',0};
char s2[] = {'b','c','e','g','i',0};
squeeze(s1, s2);
printf("%s \n", s1);
return 0;
}
void squeeze(char s1[], char s2[])
{
int i, j, k;
i = j = k = 0;
for(i;s1!='\0';i++)
{k++;
for(j;s2!='\0';j++)
{
if(s1!=s2)
s1=s1;
else
s1='\0';
}
}
} #include <stdio.h>
void squeeze(char s1[], char s2[]);
int main()
{
char s1[] = {'a','b','c','d','e','f','g','h','i','k',0};
char s2[] = {'b','c','e','g','i',0};
squeeze(s1, s2);
printf("%s\n", s1);
return 0;
}
void squeeze(char s1[], char s2[])
{
for(int i = 0; s1 != '\0'; i++)
{
for(int j = 0; s2 != '\0'; j++)
{
if(s1 == s2)
{
for(int k = i; s1 != '\0'; k++)
s1 = s1;
i--;
break;
}
}
}
} claws0n 发表于 2018-10-19 22:02
谢谢大佬{:10_254:}
页:
[1]