#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 array list if
//       it occurs before index position size, otherwise 
//       returns -1

void outputWords(words list[], int size);
// post: outputs to the monitor all words in list between 
//       0 and index position size


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)
	{
		int index = wordFound(fileWords, position, currentWord);
		if(index != -1)  // the word is in the array
			fileWords[index].count += 1;

		else  // add word 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;
}
