#include<stdio.h>#include<assert.h>#include<malloc.h>#include<memory.h>void Delete_specific_char(char * str1, char * str2){ char * phash = (char *)malloc(sizeof(char)*256); assert(phash); memset(phash, 0, 256); int i = 0; while(str2[i] != '\0' ) { phash[str2[i++]] =1; } int newp = 0; i = 0; while(str1[i] != '\0' ) { if(phash[str1[i]] ==1) { i++; } str1[newp++] = str1[i]; i++; } str1[newp ] ='\0'; free(phash);}int main(){ char a1[] = "they are student."; char a2[] = "aeiou"; Delete_specific_char(a1, a2); printf("%s",a1); printf("%s\n",a2); return 0 ;}
# Include <stdio. h> # include <malloc. h> # include <assert. h> # include <memory. h> void Delete_specific_char (char * str1, char * str2) {assert (str1); assert (str2); char * phash = (char *) malloc (sizeof (char) * 256); // map str2 to memset (phash, 0,256); int I = 0; while (str2 [I]! = '\ 0') {phash [str2 [I] = 1; I ++;} char * fast = str1; // This pointer is used to scan str1char * slow = str1; // This pointer is used to modify str1, which stores the next position int j = 0; while (fast [j]! = '\ 0') // start scanning str1 {if (phash [* fast]! = 1) // if the letter to which fast points does not exist in str2, fast and slow all point to the next {* slow = * fast; fast ++; slow ++ ;} else // if the letter that fast points to exists in str2, fast points to the next {fast ++; while (phash [* fast]) // Continue scanning, skip all consecutive characters in str2 until a non-str2 character {fast ++;} * slow = * fast; is found; // assign the non-str2 character to the slow ++ character currently pointed to by slow; // Continue scanning, fast ++ ;}} * slow = '\ 0 '; free (phash);} int main () {char a1 [] = "they are student. "; char a2 [] =" aeiouac "; Delete_specific_char (a1, a2); int I = 0; While (a1 [I]! = '\ 0') {printf ("% c", a1 [I]); I ++;} printf (": \ n"); return 0 ;}