title: Program to find Word Length Statistics
body: <p>I am expected to make a program to calculate and display statistics about the length of words in a text file. I have been provided the following file</p>
  
  <pre><code>int readFile(const char fName[], char textStr[]){
      FILE *fPtr;
      char ch;
      int size = 0;
  
      if ((fPtr = fopen(fName, "r")) == NULL) {
          fprintf(stderr, "Error, failed to open %s: ", fName);
          perror("");
          return 1;
      }
  
      while ((ch = fgetc(fPtr)) != EOF) {
          if (size &gt;= MAX_FILE - 1)
              break;
          textStr[size++] = ch;
      }
  
      textStr[size] = '\0';
  
      return size;
  }
  </code></pre>
  
  <p>I was able to verify that I can access the file using the following code</p>
  
  <pre><code>int main() {
      char str[MAX_FILE];
      int len = readFile("test.txt", str);
      if (len == -1) {
          printf("An error occurred\n");
      } else {
          printf("file read");
      }
  }
  </code></pre>
  
  <p>File <code>test.txt</code> contains</p>
  
  <pre><code>The quick brown fox jumps over the lazy dog
  </code></pre>
  
  <p>What I want to do is to get the contents of <code>test.txt</code> and find the length of each word in it something like:-</p>
  
  <pre><code>1 letter words- 0
  2 letter words - 0
  3 letter words - 3
  4 letter words -4
  </code></pre>
  
  <p>and so on...</p>