Problem viewing text file

This is a discussion on Problem viewing text file within the C++ Programming forums, part of the General Programming Boards category; The code below is a sub-program of my program. The problem it only reads the first line of the text ...

  1. #1
    Registered User
    Join Date
    Nov 2001
    Posts
    44

    Problem viewing text file

    The code below is a sub-program of my program. The problem it only reads the first line of the text file, and want it to read it all, I think you have to use the nth -1, but not sure.

    Also when viewing the text file, how do I get it just to show a certain amount of lines at a time ( 1 screen full), like DOS?

    void ViewFile()
    {
    const char * managerfile = "c:\\mfile.txt";
    clrscr();
    char buffer[256];
    ifstream managerfile (managerfile, ios::in);
    managerfile.getline (buffer,100);
    cout << buffer << endl;
    getch();
    fManagerMain();
    }
    I'm using Bloodsheds Dev-C++ Compiler.

    JamMan..

    Curious if I can live forever? CLICK HERE

  2. #2
    zen
    zen is offline
    of Zen Hall zen's Avatar
    Join Date
    Aug 2001
    Posts
    1,007
    You'll have to do something like -

    int lines=0;

    while(managerfile.getline (buffer,100))
    {
    cout << buffer << endl;
    //pause every 30 lines
    if(lines++%30==0)
    getch()
    }

    It's should be possible to calculate the number of lines per screen, but the function required will be os/compiler specific.
    zen

  3. #3
    Registered User
    Join Date
    Nov 2001
    Posts
    44
    Cheers Zen,
    Does anyone know how to just view certain lines of a text file, for example lines 14-19.
    I'm using Bloodsheds Dev-C++ Compiler.

    JamMan..

    Curious if I can live forever? CLICK HERE

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Formatting a text file...
    By dagorsul in forum C Programming
    Replies: 12
    Last Post: 05-02-2008, 04:53 AM
  2. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 07:39 AM
  3. Batch file programming
    By year2038bug in forum Tech Board
    Replies: 10
    Last Post: 09-05-2005, 04:30 PM
  4. Sorting text file problem...
    By John-m in forum C Programming
    Replies: 3
    Last Post: 10-01-2002, 05:51 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21