Storing Words from a text file
Hey I have to write a program that reads a text file that contains a list of words, 1 word per line. I have to store the unique words and count the occurrences of each unique word. When the file is completely read, I have to print the words and the number of occurrences to a text file. The output should be the words in alphabetical order along with the number of times they occur. Then print to the file some statistics.
I have to use character arrays instead of strings. I must use a linear search to determine if a word is in the array. The array is an array of structures and that the key is a char array so the string comparison must be used. The search task should be a separate function.
The search must be a separate function that returns an integer values. I cant use a for loop and the function must have only one return statement.
The linear seach looks something like this-
But Before I search I need to store, which is what I'm having problems with. Heres my store function-
int search (int list , int size, int key)
int pos = 0;
while (pos < size && list[pos] != key)
if (pos == size)
pos = -1;
Where array, is an array of structs made up of character array"word" and an integer "count". Any help on storing the words and the number of words in the array would be helpfull.
void displayFile (char fileName, words array )
int i = 0;
char line ;
cout << line << endl;
array[i].word = line;