#include <iostream>
#include <fstream>
#include <string>
using namespace std;

#define	SIZE 50    // the size of the array

struct words
{
	string word;
	int count;
};

int wordFound(words list[], int size, string word);
// post: returns the index of word in list if
//       it occurs, otherwise returns -1

void outputWords(words list[], int size);
// post: outputs to the monitor all words in list

void checkSize(int currentSize);
// post: aborts program if currentSize >= SIZE

main()
{
	words fileWords[SIZE];
	int position = 0;
	string currentWord;
	ifstream input;
	input.open("stringFile1.txt");

	while(input >> currentWord)
	{
	    // add 1 to the count for currentWord if that word is
	    // already in the array 
		int index = wordFound(fileWords, position, currentWord);
		if(index != -1)  // the word is in the array
			fileWords[index].count += 1;

        	else  // add currentWord to the array if not already there
		{	
			 // abort if the array is too small to hold a new word
			checkSize(position);
			
			// add the new word
			fileWords[position].word = currentWord; 
			fileWords[position].count = 1;
			position++;
		}
	}

	// output the word array
	outputWords(fileWords, position);
	return 0;
}
