Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Need help with a File DisplayProgram. The program asks the user for a name of a

ID: 3618096 • Letter: N

Question

Need help with a File DisplayProgram. The program asks the user for a name of a file, theprogram opens the file and displays 24 lines of text at a time andthen pauses. The user strikes a key to display the next 24 lines oftext until the end.

The problem is the code runs but only returning a few lines at atime...I believe due to the "fileName[SIZE]...1000.

Here is my code, any assistance would be greatly appreciated. Thanks in advance.

#include <iostream>
#include <fstream>
using namespace std;

int main()
{
    const int SIZE = 1000;    //Array size for file name
    char fileName[SIZE];    // Holdfile name
    char ch;               // Hold a character
    fstream file;           // File stream

    // Get file name from user
    cout << "Enter the file name you wish toopen and read: ";
    cin.getline(fileName, SIZE);

    // Open the file
    file.open(fileName, ios::in);
    if (!file)
    {
        cout << fileName<< " could not be opened. ";
        return 0;
    }

    // Get 24 lines from file and display
    char buff[1000];
    file.getline(fileName, SIZE);
    while (!file.eof())
    {
        cout << fileName;
        file.getline(fileName,SIZE);
        cout << " "
            << "(more) ";
        cin.getline(buff, sizeofbuff);
        for(int i = 0; i < 24&& file.getline(fileName, SIZE); i++);
    }
   
    // Close the file.
    file.close();

    return 0;
}


Explanation / Answer

please rate - thanks #include #include using namespace std; int main() {     const int SIZE = 1000;    //Array size for file name     char fileName[SIZE];    // Holdfile name     charch;               // Hold a character     fstreamfile;           // File stream     // Get file name from user     cout