SO here is the code I need help with, basically I need to write a program that cheks if 5 words from a input document are in a dicionary document both .txt files I made, I really tried but cant find where to start, any help would be appriciated.
#include<stdio.h>
#define WORD_AMOUNT 5
#define LETTERS_PER_WORD 10
#define CASE_OFFSET 32
#define DICT "dictionary.txt"
#define INPUT "input.txt"
void test_populate_and_print();
void test_compares();
void test_find();
void test_swap();
void test_order_alphabetically();
void test_dictionary_find_and_order();
void populate_array_from_text_file
(char array_strings[][LETTERS_PER_WORD], char file_name[]);
int is_word_in_dictionary(char word[], char file_name[]);
void print_all_words
(char array_words[][LETTERS_PER_WORD], int word_amount);
void verify_all_input_file_words_in_dictionary
(char input_words[][LETTERS_PER_WORD],
char dictionary_file[], char input_file[], int word_amount);
void organize_words_alphabetically
(char array_words[][LETTERS_PER_WORD]);
void swap_words(char word1[], char word2[]);
int compare_strings_case_insensitive(char *str1, char *str2);
int compare_strings(char *str1, char *str2);
int compare_two_letters_case_insensitive(char letter1, char letter2);
void copy_from_first_to_second(char word1[], char word2[], int string_size);
void clean_up_words(char array_words[][LETTERS_PER_WORD], int word_amount);
void start_program();
int main()
{
start_program();
return 0;
}
// Function that will be called that has the logic of the program.
//
// Self-defined functions used:
// verify_all_input_file_words_in_dictionary
// organize_words_alphabetically
// clean_up_words
// print_all_words
void start_program()
{
char input_words[WORD_AMOUNT][LETTERS_PER_WORD]={0};
printf("Verifying which words aren't in file:\n");
verify_all_input_file_words_in_dictionary(input_words,DICT,INPUT, WORD_AMOUNT);
organize_words_alphabetically(input_words);
clean_up_words(input_words, WORD_AMOUNT);
printf("Showing words found that are in file:\n");
print_all_words(input_words, WORD_AMOUNT);
}
void test_dictionary_find_and_order()
{
char input_words[WORD_AMOUNT][LETTERS_PER_WORD]={0};
verify_all_input_file_words_in_dictionary(input_words,DICT,INPUT, WORD_AMOUNT);
organize_words_alphabetically(input_words);
clean_up_words(input_words, WORD_AMOUNT);
print_all_words(input_words, WORD_AMOUNT);
}
void test_order_alphabetically()
{
char input_words[WORD_AMOUNT][LETTERS_PER_WORD]={0};
populate_array_from_text_file(input_words,"input.txt");
print_all_words(input_words, WORD_AMOUNT);
printf("\n\n");
organize_words_alphabetically(input_words);
print_all_words(input_words, WORD_AMOUNT);
}
void test_swap()
{
void swap_words(char word1[], char word2[]);
void copy_from_first_to_second(char word1[], char word2[], int string_size);
char str1[LETTERS_PER_WORD] = "str1";
char str2[LETTERS_PER_WORD] = "str2";
printf("str1:%s, str2:%s\n",str1,str2);
swap_words(str1,str2);
printf("str1:%s, str2:%s\n",str1,str2);
}
void test_populate_and_print()
{
char input_words[WORD_AMOUNT][LETTERS_PER_WORD]={0};
populate_array_from_text_file(input_words,"input.txt");
print_all_words(input_words, WORD_AMOUNT);
swap_words(input_words[0], input_words[4]);
print_all_words(input_words, WORD_AMOUNT);
}
void test_compares()
{
char str1[]="h";
char str2[]="H";
printf("Case insensitive comparison:\n%s vs. %s : %d\n"
,str1,str2,compare_strings_case_insensitive(str1,str2));
printf("Case sensitive comparison:\n%s vs. %s : %d\n"
,str1,str2,compare_strings(str1,str2));
}
void test_find()
{
int is_word_in_dictionary(char word[], char file_name[]);
char word_to_find[] = "Digg";
printf("Is word %s in dictionary:%d\n",
word_to_find,
is_word_in_dictionary(word_to_find, "dictionary.txt"));
}
// Verifies the words in the file specified by "input_file" are in
// the file "dictionary_file" and prints the words that aren't in it.
// It also populates the array input_words with the words from the
// "input_file" file that ARE in the "dictionary_file".
//
// Parameters:
// input_words = an array of strings.
// dictionary_file = the file name of the dictionary file to read.
// input_file = the file name of the input file to read.
// word_amount = amount of words in array.
//
// Self-defined functions used:
// populate_array_from_text_file
// is_word_in_dictionary
void verify_all_input_file_words_in_dictionary
(char input_words[][LETTERS_PER_WORD],
char dictionary_file[], char input_file[], int word_amount)
{
}
// Function will be used to determined whether two strings are the same
// being case insensitive.
// return 0, when there is NO difference between the two letters case insensitive.
// return 1, when there is a difference between the two letters case insensitive.
//
// Parameters:
// str1 = first string to compare.
// str2 = second string to compare.
//
// Self-defined functions used:
// compare_two_letters_case_insensitive
int compare_strings_case_insensitive(char str1[], char str2[])
{
}
// Function will compare two strings while being case sensitive.
// return 0, when there is NO difference between the two letters case sensitive.
// return positive when str1 is first in alphabetical order against str2.
// return negative when str1 is second in alphabetical order against str2.
//
// Parameters:
// str1 = first string to compare.
// str2 = second string to compare.
//
// NO self-defined functions used
int compare_strings(char *str1, char *str2)
{
}
// Compares two letters to verify that they are the same letter, regardless
// of case.
// return 0, when there is NO difference between the two letters case insensitive.
// return 1, when there is a difference between the two letters case insensitive.
//
// Parameters:
// letter1 = first character to compare.
// letter2 = second character to compare.
//
// NO self-defined functions used
int compare_two_letters_case_insensitive(char letter1, char letter2)
{
}
// Populate the array "array_strings" with the words in "file_name" file.
//
// Parameters:
// array_strings = array in which all words will be stored.
// file_name = file name of file that contains the words to be stored.
//
// NO self-defined functions used
void populate_array_from_text_file
(char array_strings[][LETTERS_PER_WORD], char file_name[])
{
}
// Function that verifies if "word" word is in the file named
// "file_name"
// return 1 when the word is in the dictionary
// return 0 when the word is not in the dictionary
//
// Parameters:
// word = the word to verify if it is in the file.
// file_name = the name of the file in which to check the word.
//
// Self-defined functions used:
// compare_strings_case_insensitive
int is_word_in_dictionary(char word[], char file_name[])
{
}
// Function that organizes alphabetically the words.
// Other considerations for the alphabetical order are:
// *Words with capital letters are first.
//
// Parameters:
// array_words = the array of words to put in alphabetical order.
//
// Self-defined functions used:
// compare_strings
// swap_words
void organize_words_alphabetically(char array_words[][LETTERS_PER_WORD])
{
}
// Copies the first string to the second string
//
// Parameters:
// word1 = the string to copy to another variable.
// word2 = will be copied to the word1 string.
// string_size = the size of the string to copy.
// This size should not be larger than the size of word2 nor word1.
//
// NO self-defined functions used
void copy_from_first_to_second(char word1[], char word2[], int string_size)
{
}
// Function that swaps the two strings given.
// Parameters:
// word1 = first string
// word2 = second string
//
// Self-defined functions used:
// copy_from_first_to_second
void swap_words(char word1[], char word2[])
{
}
// Function that prints all the words in the array.
//
// Parameters:
// array_words = the array of words to print out.
// word_amount = the amount of words in the array.
//
// NO self-defined functions used
void print_all_words(char array_words[][LETTERS_PER_WORD], int word_amount)
{
}
// Function that moves down in the array the position of a certain key value,
// like a null word.
//
// Parameters:
// array_words = the array of words.
// word_amount = the amount of words in the array.
//
// Self-defined functions used:
// swap_words
void clean_up_words(char array_words[][LETTERS_PER_WORD], int word_amount)
{
}