Jumping to a new page in the output file

This is a discussion on Jumping to a new page in the output file within the C++ Programming forums, part of the General Programming Boards category; How would I print enough blank lines to an output file when the data file has an unknown number of ...

  1. #1
    Registered User
    Join Date
    Aug 2003
    Posts
    3

    Jumping to a new page in the output file

    How would I print enough blank lines to an output file when the data file has an unknown number of entries? ( I can have multiple arrays on a page, but output for an individual array can not be split between two pages.)

  2. #2
    Pursuing knowledge confuted's Avatar
    Join Date
    Jun 2002
    Posts
    1,916
    there aren't any pages in a text file. Try opening something large in Notepad (or the Linux equivalent... KWrite, maybe)
    Away.

  3. #3
    Registered User
    Join Date
    Aug 2003
    Posts
    3
    when you print a large file even in Notepad, it still will print on multiple pages...my printer prints 65 lines/page.

  4. #4
    Registered User dalek's Avatar
    Join Date
    May 2003
    Posts
    135
    Yes, but in the file itself it doesn't have a concept of seperate pages. You usually need to tell your printer to form feed, by sending it a ^L character.

    For instance you may set the program up with a page size of 65 lines, once 65 lines have been printed - send the form feed.

    But I guess it depends on what platform/compiler your using because I am sure the Win32 API for example has a more elegant method.

  5. #5
    Registered User dalek's Avatar
    Join Date
    May 2003
    Posts
    135
    Sorry - I had just been doing shell scripts - ignore the ^L, it should be '\f'..

    You should send the form feed character for C/C++ which is of course '\f'.

    I am not near a compiler right now, but I snarfed this code from a site that should do what you want.
    Code:
    #include<iostream>
    #include<fstream>
    
    using namespace std;
    
    int main(void)
    {   
        cout << "Started" << endl;
        ofstream printer1;
        printer1.open ("LPT1", ios::out);
    
        for (int count = 1; count <= 65; count++)        // to fill page
        {
            printer1 << "testing" << endl;
        }
        printer1 << '\f' << endl;                       // form feed
        printer1.close();
        cout << "Finished printing to LPT1 " << endl;                   // finished
    
        return 0;
    }
    EDIT: This code assumes that your printer is connected on port LPT1, if you are on a network, you can reference the printer using the network pathname.. something like "//PRINTERHOST/PRINTER"
    Last edited by dalek; 08-05-2003 at 12:10 AM.

  6. #6
    Registered User
    Join Date
    Aug 2003
    Posts
    3

    Thumbs up

    Thank you, that helped a lot
    I appreciate it.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Can we have vector of vector?
    By ketu1 in forum C++ Programming
    Replies: 24
    Last Post: 01-03-2008, 04:02 AM
  2. simulate Grep command in Unix using C
    By laxmi in forum C Programming
    Replies: 6
    Last Post: 05-10-2002, 04:10 PM
  3. what does this mean to you?
    By pkananen in forum C++ Programming
    Replies: 8
    Last Post: 02-04-2002, 02:58 PM
  4. Need a suggestion on a school project..
    By Screwz Luse in forum C Programming
    Replies: 5
    Last Post: 11-27-2001, 01:58 AM
  5. Simple File Creation Algorithm
    By muffin in forum C Programming
    Replies: 13
    Last Post: 08-24-2001, 03:28 PM

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