I need to write just a function that counts the number of integers in an already opened and good text file.
a. Assume there is a text file with a large number of integers divided by spaces
b. Write a function called analyzeFile that accepts a previously opened ifstream file object as a parameter, and counts the number of integers in the file.
c. It does not need to do anything with the integers, but it must count exactly the correct number of integers in the file and return that number to the calling function.
d. It also does not need to manipulate the file operations themselves, so it does not need to close the file or conduct any other actions other than counting the integers and returning the number of them.
Thank you for any help on my problem!
Edit: Here is what I have as a function do far, is it right, I don't know:
int analizeFile (ifstream &inf, const string &fileName) {
int count = 1;
int num;
fin.open(fileName.c_str() );
fin >> num;
while (fin.good() ) {
fin>> num;
count ++;
}
return count;
}