1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
|
#include <iostream>
#include <fstream>
#include <string>
#include <algorithm>
using namespace std;
//Purpose: check number of command line arguments, display error, get words from file, save to memory, close file, analyze metrics and display
int main(int argc, char *argv[]){
if(argc < 2){
cout << "Correct usage: " << endl;
}else{
//calls getWords to read file
getWords(maxSize, wordsArray, argv[1]);
//get words from file here -- ????
//close file
fileIn.close();
//display metrics (doing this later)
return 0;
}
//Purpose: input file for reading, otherwise display error message. Read words from file, store into array of strings. Return the number of words in the string array.
int getWords(int maxSize, string wordsArray[], string filename){
int totalWords = 0;
int counter = 0;
int i;
//open input file for reading
if(!fileIn)
cerr << "Sorry, could not open " << filename << " for reading << endl;
else{
//get each words one at a time and read into wordsArray
while(fileIn, wordsArray[counter]){
counter++;
}
//to find the count of words in the string array
for(int i = 0, !wordsArray[i].empty(); i++){
++totalWords;
}
}
return totalWords;
}
//Purpose: accept the array of strings and integer size, like last word alphabetically and return it (ex: I love you --> last word is "you")
string findMaxWord(int maxSize, string wordsArray[]){
int N = sizeof(wordsArray)/sizeof(wordsArray[0]) - 1;
sort(begin(wordsArray),end(wordsArray));
for(int i = N; i >= N; i--){
cout << wordsArray[i] << endl;
}
lastWord = wordsArray[i]; //I dont even think you can do this? Im trying to store the last word of the string array into the string and return it
return lastWord;
}
|