title: Counting words in C
body: <p>I'm trying to create a C code that uses the functions fgets(), strncmp() and strlen(), mainly to get a better understanding of them. The goal is to type in a text using fgets(), to shut it off with an end of file mark, and to count how many times a word (set in program arguments) occurs. This is what I got so far, but it's not working for me. I'm having a hard time using strings and arrays, as I'm a beginner C programmer.</p>
  
  <pre><code>int main(int argc, char *argv[])
  {
      int i, N, wrdcnt = 0;
      char buf[1026], *eof = "#EOF";
  
      N = strlen(argv[1]);
  
      while (strcmp(*buf, *eof) != 0)
      {
          fgets(buf, 1025, stdin);
  
          for (i = 0; i &lt; (strlen(*buf) - N); i++)
          {
              if (strncmp(buf[i], argv[1], N) == 0)
              {
                  wrdcnt++;
              }
          }
      }
      printf("%d", wrdcnt);
  
      return 0;
  }
  </code></pre>
  
  <p>I could really use some help!</p>