Esempio n. 1
0
/*
 * BOOLEAN *find_synonym(char *word, FILE *p_dictionary, long *letters, char *buff)
 *
 * Finds Identical word in the dictionary file.
 * Returns a true if found a synonym(that will be saved to buff) or false
 * if failed.
 *
 * params: char *word - the word that needs to be replaced.
 * 		   FILE *p_dictionary - pointer to the dictionary text file.
 * 		   long *letters - Array that the function set_letters_pos returned.
 * 		   char *buff - the string that the synonym will be saved to.
 *
 */
BOOLEAN find_synonym(char *word, FILE *p_dictionary, long *letters, char *buff)
{
	long char_pos;
	char first_letter = char_to_upper(*word);

	/* set file pointer position to that letter if it exists */
	if((char_pos = *(letters + first_letter - CAP_A)) == -1)
	{
		if(PRINT_ERROR)
		{
			fprintf(stderr, "%c wasn't found\n", first_letter);
			PRINT_FILE_LINE();
		}
		return false;
	}

	fseek(p_dictionary, char_pos, SEEK_SET);
	/* set file pointer to next line and start comparing */
	next_line(p_dictionary);
	if(cmp_words(word, p_dictionary) == false)
	{
		return false;
	}

	return get_synonym(p_dictionary, buff);
}
	///
	/// Converts the character @a c to upercase, returning the result
	/// @param c the character to convert to upercase
	///
	VALKNUT_FORCE_INLINE tchar tchar_to_upper(tchar c){
		return (tchar) char_to_upper(c);
	}