include iostream char del_words char start size_t len char filter if l

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include <iostream>
char * del_words(char * start, size_t len, char * filter)
{
if(len == 0) return NULL;
char * l, *r, *lf, *rf;
lf = rf = filter;
bool b = true;
char * result = new char [len];
char * result_pos = result;
for( r = l = start; *l != '\0'; l = r, rf = lf, b = true)
{
while (*r == ' ') *(result_pos++) = *(r++);
while (*r != '\0' && *r != ' ')
{
if ( *rf == '\0' ) b = false;
else if( *r == *rf ) rf++;
r ++;
};
if (*rf == '\0' ) b = false;
if( b )
{
while ( l != r )
{
*result_pos = *l;
l ++;
result_pos ++;
}
}
}
return result;
}
int main()
{
char * str = "ADDD ghjs kllla sdsd 0sl orooo asdooo";
char * result = del_words(str, 100, "ooo");
std::cout << str << std::endl;
std::cout << result << std::endl;
delete [] result;
return 0;
}