I am trying to write a program that reads words from files and then puts them into arrays and then does a count on certain words. I have moved stuff around and really I am not sure that I am even on the right track. Could someone please look at this for me and tell me what I have wrong. It will not run at all. Also I am having trouble with the counting of the certain word. Any help would be greatly appreciated. This is what I have so far. I think I may have things in the wrong places. I am going to put the instruction for the part that I think I have done.
#include "stdafx.h"
#include <iostream>
#include <string>
#include <fstream>
using namespace globalType;
void printResults();
print word_count(std::string);
int find(std::string[], int word_count, std::string a_word)
{
for(int i=0; i < word_count; ++i) if(words[i] == a_word) return i;
return-1; // did not find word
}
int main()
{
const int MAX_WORDS = 100;
std::string words[MAX_WORDS];
int words[100][length of longest word +1]
std::ifstream("SelectWords.txt");
while(file >> words[word_count]) ++word_count; //word_count contains number of words read
int words[100][30];
int word_count[100]={0}; //initialize to zeros
int pos = find( words, word_count, word_read_from_file);
if(pos != -1) ++word_count; //if found, increment the count <<<<<<<< I am having trouble here
system("pause");
return 0;
}
INSTRUCTIONS:
Read the words from a file named “SelectWords.txt” into a 100-element array of strings.
Declare and initialize to zeroes a parallel array of whole numbers for word counts
Declare and initialize to zeroes a parallel array of doubles for word frequencies.
Declare two strings to hold the shortest and longest words in the data file. Initialize the shortest word to “thisisarunonsentencewithlotsofletters” and the longest word to “a”.
Declare a whole number variable to hold the total word count, and initialize it to zero.