I have an array to filter.
Example:
str = "hellothere" and filter = "eo". What to do when i need to filter?
void filter_str(char* str, char* filter, char*result)
{
while(*str)
{
if() //If the current character in str is one to be filter.
{
*str++;
}
else
{
*result++ = *str++;
}
}
*result = '\0';
}
I just can’t figure out how to check if the current character is one that needs to be filter. Since the filter can be more than one character, such as “eo”. How do I check both “e” and “o” every loop, and then reset filter back to “e” at the start.
I wanted to make a pointer to the start of filter, then use that at the end of the while to go back to the start of filter. But I am not sure how to make it check *str against all the characters to be filtered.
In this case a function has already been written that will do the hard work for you
In general this is the answer to any question where you have processing that is too complex for you to handle. Write a function to solve the ‘inner’ problem, and then use that function in the ‘outer’ problem. In this case the inner problem is finding a character in a string, and the outer problem is the filtering operation you are doing. You are just lucky that the inner problem has already been solved for you.