Hello,
I'm new here but I need a little help please. I've gotten this program to mostly work correctly except for what seems like one small detail. My program is supposed to ask the user to enter a file name, open it and display its contents 24 lines at a time. It should wait for the user to strike a key before showing the next 24 lines. It does all of that except after the first 24 lines, it says what I want it to say which is "Press any key to continue" but it doesn't wait for the user to press any key. Instead, it waits for the user after the NEXT 24 lines and every 24 lines after that. I will paste my code here. Can anyone tell me what I might be overlooking? Thank you!
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
const int SIZE = 51;
char fileName[SIZE];
char line[80];
ifstream file;
cout << "Enter a file name: ";
cin >> fileName;
file.open(fileName, ios::in);
for(int i=1; !file.eof(); i++)
{
file.getline(line, 80);
cout << i <<": " << line << endl;
if (i % 24 == 0)
{
cout << "Press any key to continue." << endl;
getchar();
}
}
file.close();
return 0;
}