示例#1
0
void load_dictionary (const char *dictionary_name, hashset *hashset) {
   if (dictionary_name == NULL) return;
   DEBUGF ('m', "dictionary_name = \"%s\", hashset = %p\n",
           dictionary_name, hashset);
   FILE *dictionary = fopen(dictionary_name, "r");
   char buffer[BUFFER_SIZE];
   while(fgets(buffer, BUFFER_SIZE + 1, dictionary) != NULL){
      buffer[strcspn(buffer, "\n")] = '\0';
      const char *temp = strdup(buffer);
      put_hashset(hashset, temp);
   }
   fclose(dictionary);
}
示例#2
0
void load_dictionary (char *dictionary_name, hashset *hashset) {
   if (dictionary_name == NULL) return;
   DEBUGF ('m', "dictionary_name = \"%s\", hashset = %p\n",
           dictionary_name, hashset);
   FILE *dict = open_infile(dictionary_name);
   char buffer[1024];
   while(fgets(buffer, sizeof buffer, dict) != NULL){
      if(buffer[strlen(buffer)-1] == '\n')
         buffer[strlen(buffer)-1] = '\0';
      char* word = strdup(buffer);
      assert(word != NULL);
      put_hashset(hashset, word);
   }
   fclose(dict);
}
示例#3
0
void load_dictionary (const char *dictionary_name, hashset *hashset) {
   if (dictionary_name == NULL) return;
   DEBUGF ('m', "dictionary_name = \"%s\", hashset = %p\n",
           dictionary_name, hashset);
   //STUBPRINTF ("Open dictionary, load it, close it\n");
   FILE *dict = fopen(dictionary_name, "r");
   char buffer[100];
   if (dict != NULL) {
      while(fgets(buffer,sizeof(buffer), dict)) {
         char *nlptr = strchr(buffer, '\n');
         if(nlptr) *nlptr = '\0';
         char *word = strdup(buffer);
         put_hashset(hashset, word);
      }
   }
   fclose(dict);
}
示例#4
0
void load_dictionary (char *dictionary_name, hashset *hashset) {
   if (dictionary_name == NULL) return;
   FILE *dictionary = open_infile(dictionary_name);
   if (dictionary == NULL) return;
   for(;;){
      char buffer[1024];
      char *linepos = fgets(buffer, 1023, dictionary);
      if (linepos == NULL){
         break;
      }
      int i = 0;
      for(; buffer[i] != '\n'; i++){}
      buffer[i] = '\0';
      put_hashset(hashset, buffer);
   }
   fclose(dictionary);
}
示例#5
0
void load_dictionary (const char *dictionary_name, hashset *hashset) {
   if (dictionary_name == NULL) return;
   DEBUGF ('m', "dictionary_name = \"%s\", hashset = %p\n",
           dictionary_name, hashset);
   char buff[1024];
   FILE *dictionary = open_infile(dictionary_name);
   assert(dictionary != NULL);
   int linenr = 1, j_index = 0;
   for(linenr = 1; ; linenr++){
      char *line_pos = fgets(buff, sizeof buff, dictionary);
      //check to see if words scanned are valid
      if (line_pos == NULL) break;
      line_pos = strchr (buff, '\n');
      //make sure the new line character is inserted correctly
      if (line_pos == NULL){
         fflush(NULL);
         fprintf (stderr, "%s: %s[%d]: broken line\n", Exec_Name,
                  dictionary_name, linenr);
         fflush(NULL);
         Exit_Status = 2;
      }else {
         *line_pos = '\0';
      }
      //line_pos is fed the buffer's string
      line_pos = strdup(buff);
      assert (line_pos != NULL);
      //puts the input into the hashset
      put_hashset(hashset, line_pos);
      //frees the line_position
      free(line_pos);
      j_index++;
   }
   fclose(dictionary);
   printf("# of words added: %d\n", j_index);
   //STUBPRINTF ("Open dictionary, load it, close it\n");
}