转自:http://www.cnblogs.com/tolimit/p/4202959.html
/*************************************************************************
> File Name: test.c
> Author: ToLiMit
> Mail: 348958453@qq.com
> Created Time: Sun 04 Jan 2015 06:20:05 PM PST
************************************************************************/ #include<stdio.h> void delete_str_char (char * main_str, char * sub_str)
{
if ((main_str == NULL) || (sub_str == NULL))
return; char * sub_index = sub_str;
char * main_index = main_str;
char bitmap[] = {};
char * str = (char *)malloc (strlen (str) + );
char * index = str;
memset (str, , strlen (str) + ); while (*sub_index != '\0') {
char suffix = ((*sub_index) / ) - ;
char offset = (*sub_index) % ; bitmap[suffix] |= (0x1 << ( - offset));
sub_index++;
} while (*main_index != '\0') {
char suffix = ((*main_index) / ) - ;
char offset = (*main_index) % ; if ((bitmap[suffix] & (0x1 << ( - offset))) == ) {
*index = *main_index;
index++;
}
main_index++;
} *index = '\0';
memcpy (main_str, str, strlen (str) + );
free (str);
return;
} int main (int argc, char * argv[])
{
char test[] = "aabcdaaaaabcaacb"; delete_str_char (test, "bcd");
printf ("%s\n", test);
return ;
}