Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int info(const char *dictionary, int *shortest, int *longest, int *num_words)
- {
- FILE *dic; /* Stores the dictionary */
- char buffer[LONGEST_WORD]; /* Stores the word */
- int count = 0;
- *longest = 0;
- *shortest = MAX_INT;
- dic = fopen(dictionary, "rt"); /* Opens the dictionary for reading */
- if (dic) /* Checks if dictionary opened correctly */
- {
- while (!feof(dic)) /* While there are lines to read */
- {
- if (fgets(buffer, LONGEST_WORD, dic)) /* Read in line by line */
- {
- int length = strlen(buffer) - 1; /* Length of the word */
- if (length < *shortest) /* If the word is shorter than the shortest */
- *shortest = length; /* Replace */
- if (length > *longest) /* If the word is longer than the longest */
- *longest = length; /* Replace */
- count++; /* Increase word count */
- }
- }
- *num_words = count; /* Sets the word count to the pointer passed */
- }
- else
- return FILE_ERR_OPEN; /* File didn't open correctly */
- fclose(dic); /* Close dictionary */
- return FILE_OK; /* File opened correctly */
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement