將字符串s1中的任何與字符串s2中字符匹配的字符都刪除

編寫一個程序,將字符串s1中的任何與字符串s2中字符匹配的字符都刪除。數組

函數原型:void my_squeeze(char s1[], char s2[])ide

#include <stdio.h>函數

void my_squeeze(char s1[], char s2[])spa

{字符串

int i = 0;原型

int j = 0;it

while (s2[j])io

{class

while(s1[i])程序

{

if (s2[j]==s1[i])

{

while (s1[i+1])

{

s1[i] = s1[i + 1];

i++;

}

s1[i] = '\0';

}

i++;

}

i = 0;

j++;

}

}

int main()

{

char arr1[] = "qwdcgje"; 

char arr2[] = "abcdefg";

        /*char arr1[] = { 'q', 'w', 'd', 'c', 'g', 'j', 'e' };

char arr2[] = { 'a', 'b', 'c', 'd', 'e', 'f' }; 字符數組後面沒有0,不知道何時停下,因此出錯*/

my_squeeze(arr1, arr2);

printf("%s\n", arr1);

system("pause");

return 0;

}

相關文章
相關標籤/搜索