title: fast string search to find string array element which matches the givven pattern
body: <p>I have an array of constant strings which I iterate through to find an index of element which is a string that contains a search pattern. Which search algorithm should I choose to improve the speed of finding this element? I am not limited in time before running the application for preparing the look up tables if any are necessary.</p>
  
  <p>I corrected a question - I am not doing exact string match - I am searching for pattern inside the element, which is in an array</p>
  
  <pre><code>array of strings:
  [0] Red fox jumps over the fence
  [1] Blue table
  [2] Red flowers on the fence
  </code></pre>
  
  <p>I need to find an element which contains word 'table' - in this case its element 1</p>
  
  <p>I do like 50000 iterations of a set of 30 array which could contain up to 30000 strings of not less than 128 characters. Now I am using good-old <code>strstr</code> brute force which is too slow...</p>
  
  <p>Ok, posting a part of my function, the first <code>strstr</code> - looks up in an uncut array of lines if there are any occurrences, then the brute search follows. I know I can speed this part, but I am not doing optimization on this approach...</p>
  
  <pre><code>// sheets[i].buffer - contains a page of a text which is split into lines
  // fullfunccall - is the pattern
  // sheets[i].cells[k] - are the pointers to lines in a buffer
  
  for( i=0; i&lt;sheetcount; i++) {
    if( i!= currsheet &amp;&amp; sheets[i].name &amp;&amp; sheets[i].name[0] != '\0') {
      if( strstr(sheets[i].buffer, fullfunccall )) {
        usedexternally = 1;
  
        int foundatleastone = 0;
        for( k=0; k&lt;sheets[i].numcells; k++ ) {
          strncpy_s(testline, MAX_LINE_SIZE, sheets[i].cells[k]-&gt;line, sheets[i].cells[k]-&gt;linesize);
          testline[sheets[i].cells[k]-&gt;linesize] = '\0';
  
          if( strstr(testline, fullfunccall )) {
            dependency_num++;
  
            if( dependency_num &gt;= MAX_CELL_DEPENDENCIES-1) {
              printf("allocation for sheet cell dependencies is insuficcient\n");
              return;
            }
  
            sheets[currsheet].cells[currcellposinsheet]-&gt;numdeps = dependency_num+1;
            foundatleastone++;
            sheets[currsheet].cells[currcellposinsheet]-&gt;deps[dependency_num] = &amp;sheets[i].cells[k];
          }
        }
  
        if( foundatleastone == 0 ) {
          printf("error locating dependency for external func: %s\n", fullfunccall );
          return;
        }
      }
    };
  }
  </code></pre>