Hello, I am trying to create a loop that will read a file containing an array of strings into an array, where I can then edit individual words. I've created a "while" loop that copies the file and counts words, but I want it to keep a count of the total number of characters being read from the file (including spaces " ") as well. That is what the int count is for. Can anyone help me to fix this loop?
#include <iostream>
#include <fstream>
usingnamespace std;
int readFile(char storyText[][32])
{
cout << "Please enter the filename: ";
cin >> fileName;
//open file using filename input by user
ifstream fin(fileName);
//check for errors
if (fin.fail())
{
cout << "Error opening file \""
<< fileName
<< "\""
<< endl;
}
//copy contents of file into array
int wordCount = 0;
int count = 0; //this is the variable I want to include
while (fin >> storyText[wordCount])
{
wordCount++;
}
cout << "wordCount: " << wordCount << endl;
cout << "count: " << count << endl;
//don't forget to close file
fin.close();
return;
}
int main()
{
char storyText[256][32];
int wordCount = readFile(storyText);