title: Head First C Program ( text search program)
body: <p>I have a question regarding the below program from Head First C.
  In the book under main function the writer did not used <code>search_for[strlen(search_for) - 1] = '\0';</code>; still his program ran fine. However when I used original version of the program (as per book),it was not able to find the text which I input. I got the below version from github(which can find text in string) but I still can't understand why it was used . If somebody can explain me I will really appreciate.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;string.h&gt;
  
  char tracks[][80] = {
      "I left my heart in Harvad Med School",
      "Newark, Newark -  Wonderful town",
      "Dancing with a Dork",
      "From here to maternity",
      "The girl from Iwo Jima",
  };
  
  void find_track(char search_for[])
  {
      int i;
      for (i = 0; i &lt; 5; i++) {
          if (strstr(tracks[i], search_for))
              printf("Track %i: '%s'\n", i, tracks[i]);
      }
  }
  
  int main()
  {
      char search_for[80];
      printf("Search for :");
      fgets(search_for, 80, stdin);
      search_for[strlen(search_for) - 1] = '\0';
      find_track(search_for);
      return 0;
  }
  </code></pre>