title: Searching a word in a 2d array in c programming
body: <p>I am trying to set up a program that when you type /s then a movie title (ex. /s Green Mile it searches for that movie title in the movies array but my strstr function is not working. Also /a adds movie /r shows all movies in database and /q quits program.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;string.h&gt;
  main() {
  
      char movies[1000][64];
      int i;
      int j = 1;
      int k = 0;
      int counter = 0;
      char buffer[64];
      char buffer2[64];
      int len;
  
      do {
        printf("Enter command for movie database:\n");
        fgets(buffer, 64, stdin);
  
        if (buffer[1] == 'a') {
           len = strlen(buffer);
           if (buffer[len - 1] == '\n')
               buffer[len - 1] = '\0';
  
           for(i=3; i&lt;sizeof(buffer); i++) {
              movies[counter][k] = buffer[i];
              k++;
           }
           printf("You have chosen to enter a movie in the database.\n");
           printf("The movie added to the database is: %s\n", &amp;movies[counter][0]);
           counter++;
           k = 0;
        }
  
        if (buffer[1] == 'q') {
           printf("You have chosen to quit.\n");
           printf("Goodbye.\n");
        }
  
        if (buffer[1] == 's') {
           for(i=2; i&lt;sizeof(buffer); i++) {
              buffer2[k] = buffer[i];
              k++;
           }
  
           for (i = 0; i &lt; counter; i++) {
              if (strstr(movies[i], buffer2) != NULL) {
                 printf("Found %s in position %d,%s\n", buffer2, i + 1, movies[i]);
                 printf("Index of Movie is %d.\n", i + 1);
              }
           }
           k = 0;
        }
  
        if (buffer[1] == 'r') {
           printf("You have choosen to report movies in database\n");
           printf("These are the movies you have watched:\n");
           for( i = 0; i &lt; counter; i++ ) {
              printf("%d: %s\n", j,  &amp;movies[i][0]);
           j++;
           }
        printf("\n");
        j = 1;
        }
     } while (buffer[1] != 'q');
  }
  </code></pre>