Thread: Problem viewing text file

  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
    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, 03:53 AM
  2. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  3. Batch file programming
    By year2038bug in forum Tech Board
    Replies: 10
    Last Post: 09-05-2005, 03:30 PM
  4. Sorting text file problem...
    By John-m in forum C Programming
    Replies: 3
    Last Post: 10-01-2002, 04:51 PM