C Programming - Remove Characters within a String

The characters to be removed from a string is given as another string.

Your comments are valuable!!

Solution:



void remove(char src[], char del[])
{
char hash[26] = {0};
char *fsrc = del,*fdst;
int count;
while(*fsrc) {
hash[*fsrc - 'a'] = 1;
fsrc++;
}
fsrc = fdst = src;
while(*fsrc) {
if ( (*fsrc == ' ') || ( hash[*fsrc - 'a'] == 0 ) ) {
*fdst = *fsrc;
fdst++;
}
fsrc++;
}
*fdst = '\0';
}

Labels:


About this entry