转自: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[32] = {0}; char * str = (char *)malloc (strlen (str) + 1); char * index = str; memset (str, 0, strlen (str) + 1); while (*sub_index != '\0') { char suffix = ((*sub_index) / 8) - 1; char offset = (*sub_index) % 8; bitmap[suffix] |= (0x1 << (8 - offset)); sub_index++; } while (*main_index != '\0') { char suffix = ((*main_index) / 8) - 1; char offset = (*main_index) % 8; if ((bitmap[suffix] & (0x1 << (8 - offset))) == 0) { *index = *main_index; index++; } main_index++; } *index = '\0'; memcpy (main_str, str, strlen (str) + 1); free (str); return; } int main (int argc, char * argv[]) { char test[] = "aabcdaaaaabcaacb"; delete_str_char (test, "bcd"); printf ("%s\n", test); return 0; }
【作者】
张昺华
【新浪微博】 张昺华--sky
【twitter】 @sky2030_
【facebook】 张昺华 zhangbinghua
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利.