#include <stdio.h>
#include <stdlib.h>
//编写squeeze函数(s1,s2),将字符串s1中任何与s2中字符匹配的字符都删除
int test(char ch,char s2[]);
void squeeze(char s1[],char s2[]);
int main()
{
char s1[] = {'a','b','2','3','5','d','\0'};
char s2[] = {'1','2','3','4','5','6','7','8','9','0','\0'};
squeeze(s1,s2);
//printf("%d",test('3',s2));
printf("%s",s1);
return 0;
}
void squeeze(char s1[],char s2[])
{
int i,j;
for(i = j= 0;s1[i] != '\0';i++)
if(!test(s1[i],s2))
s1[j++] = s1[i];
s1[j] = '\0';
}
//用于监测某个char型变量是否包含在另一个char型数组中
int test(char ch,char s2[])
{
int i ,n = 0;
for(i = 0; s2[i] != '\0'; i ++)
if(ch == s2[i])
{
n = 1;
break;
}
return n;
}
squeeze函数编写
最新推荐文章于 2022-11-30 23:08:33 发布