Advertisement
Guest User

Untitled

a guest
May 10th, 2016
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.19 KB | None | 0 0
  1. #include <stdbool.h>
  2. #include "dictionary.h"
  3. #include <stdio.h>
  4. #include <cs50.h>
  5. #include <ctype.h>
  6. #include <string.h>
  7. #include <stdlib.h>
  8.  
  9. int dictionary_size=1;
  10. FILE* dictfile;
  11.  
  12. /**
  13.  * Returns true if word is in dictionary else false.
  14.  */
  15. bool check(const char* word){
  16.    
  17.     return true;
  18. }
  19.  
  20. /**
  21.  * Loads dictionary into memory.  Returns true if successful else false.
  22.  */
  23. bool load(const char* dictionary){
  24.     dictfile = fopen(dictionary, "r");
  25.     char symw;
  26.     if(dictfile == NULL){
  27.         return false;
  28.     }
  29.     while(feof(dictfile) == 0){
  30.         symw = fgetc(dictfile);
  31.         if(symw == EOF){
  32.             break;
  33.         }else if(symw == '\n'){
  34.             dictionary_size++;
  35.         }
  36.     }
  37.     return true;
  38. }
  39.  
  40. /**
  41.  * Returns number of words in dictionary if loaded else 0 if not yet loaded.
  42.  */
  43. unsigned int size(void){
  44.     if(dictionary_size != 0){
  45.         return dictionary_size;
  46.     }else{
  47.         return 0;
  48.     }
  49. }
  50.  
  51. /**
  52.  * Unloads dictionary from memory.  Returns true if successful else false.
  53.  */
  54. bool unload(void){
  55.     if(dictfile != NULL || dictfile == NULL){
  56.         fclose(dictfile);
  57.         return true;
  58.     }else return false;
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement