title: Counting words in a word count program from filename
body: <p>I seem to be able to get the lines, characters and spaces correctly. However, I'm having a hard time figuring out how to count words. They don't have to be in dictionary form; for example, <code>fdasf fdjsak fea</code> would be three words.</p>
  
  <p>This is what I have:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  int main(int argc, char* argv[]) {
    int ccount = 0;
    int wcount = 1;
    int lcount = 0;
    int scount = 0;
  
    char* filename = argv[1];
    printf("filename is: %s\n", filename);
  
    FILE* infile;
    infile = fopen(filename, "r");
  
    if (infile == NULL) {
      printf("%s: is not a valid file\n", filename);
      return -1;
    }
  
    char c;
    while ((c = fgetc(infile)) != EOF) {
      if (c == ' ') {
        wcount++;
      }
      if (c == '\n') {
        lcount++;
      }
      if (c != ' ' || c != '\n') {
        ccount++;
      }
      if (c == ' ') {
        scount ++;
      }
    }
  
    printf("total number of lines: %d\n", lcount);
    printf("total number of characters: %d \n", ccount);
    printf("total number of non-whitespace characters: %d \n", scount );
    printf("total number of words: %d \n", wcount);
  
    return 0;
  }
  </code></pre>