/*replace all words with synonyms*/
void replace_words(FILE *fp_sc, FILE *fp_dict, char *search_array , char** after_replace) {
	
	char word[WORD_SIZE] = "";
	int word_location = -1;

	/*get file length*/
	fseek(fp_sc, 0L, SEEK_END);
	size_t file_size = ftell(fp_sc);
	fseek(fp_sc, 0L, SEEK_SET);
	/*in case the synonyms are bigger than origianl word allocate more memory*/
	char *whole_file = malloc(file_size*1.5);
	strcpy(whole_file, "");
	while (!feof(fp_sc) && get_next_word(fp_sc, word) != NULL){
		if (word != "") {
			word_location = find_word_index(word, search_array, word_amount);
			if (word_location >= 0) {/* found */

				strcat(whole_file, get_synonym(fp_dict, word_location));
			}
			else {
				strcat(whole_file, word);
			}
		}
		strcat(whole_file, get_non_alpha(fp_sc));
		strcpy(word, ""); /* clear the word*/
	} 

	*after_replace = whole_file;
}
예제 #2
0
void add_word(struct keys *kd, char *word) {
  int index = find_word_index(kd, word);

  if (index > -1) {
    increment_word(kd, word, index);
  }
  else {
    add_entry(kd, word);
  }
}