In the end, you need to compare every element in the final array with each of the search strings patterns. But there may be more efficient ways to do that and ways to avoid some comparisons if you only care to find whether the patterns exist at least once. For example:
string patterns[] = {"string1", "string2", "string3"};
int hasFoundElement[] = {0, 0, 0};
int numElementsFound = 0;
for (int i = 0; i < arrayLength; i++)
{
for (int j = 0; j < patternsLength; j++)
{
if (!hasFoundElement[j] &&
strcmp(patterns[j], array[i]) == 0)
{
hasFoundElement[j] = 1;
numElementsFound++;
if (numElementsFound == patternsLength)
{
return true;
}
}
}
return false;
regexec()set of functions. Thegrep -Fmode can search (fast) for multiple words at the same time too, without requiring the user to explicitly use regex notation.O(1)response on average, i.e. you would basically do threeO(1)lookups. If you are actually doing something like searching a sentence in a large text, then you would have to use more complex structures, probably something based on a trie.