Advertisement
Guest User

asd

a guest
Nov 26th, 2014
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.48 KB | None | 0 0
  1. int info(const char *dictionary, int *shortest, int *longest, int *num_words)
  2. {
  3.   FILE *dic;                         /* Stores the dictionary                 */
  4.   char buffer[LONGEST_WORD];         /* Stores the word                       */
  5.   int count = 0;
  6.   *longest = 0;
  7.   *shortest = MAX_INT;
  8.  
  9.   dic = fopen(dictionary, "rt");     /* Opens the dictionary for reading      */
  10.   if (dic)                           /* Checks if dictionary opened correctly */
  11.   {
  12.     while (!feof(dic))               /* While there are lines to read         */
  13.     {
  14.       if (fgets(buffer, LONGEST_WORD, dic))         /* Read in line by line   */
  15.       {
  16.         int length = strlen(buffer) - 1;            /* Length of the word     */
  17.  
  18.         if (length < *shortest)   /* If the word is shorter than the shortest */
  19.           *shortest = length;     /* Replace                                  */
  20.  
  21.         if (length > *longest)    /* If the word is longer than the longest   */
  22.           *longest = length;      /* Replace                                  */
  23.  
  24.         count++;                  /* Increase word count                      */
  25.       }
  26.     }
  27.  
  28.     *num_words = count;          /* Sets the word count to the pointer passed */
  29.   }
  30.  
  31.   else
  32.     return FILE_ERR_OPEN;                       /* File didn't open correctly */
  33.  
  34.   fclose(dic);                                  /* Close dictionary           */
  35.   return FILE_OK;                               /* File opened correctly      */
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement