Share your knowledge at the LQ Wiki.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 03-25-2004, 08:29 PM   #1
LQ Newbie
Registered: Mar 2004
Posts: 13

Rep: Reputation: 0
C: How can i print out the content of a file in pages?

I am writing a C program for Linux.
If the content of a file is too large for one terminal screen, how can i print the content in pages?
Just like when we use the "man" function.
Old 03-25-2004, 08:46 PM   #2
Registered: Mar 2004
Location: Massachusetts
Distribution: Debian
Posts: 557

Rep: Reputation: 42
As a user I'd be most happy if you piped the output into $PAGER, or 'more' by default. This would look like

#include <stdlib.h>
#include <stdio.h>

#define NLINES 500

int main()
        char* pager = getenv("PAGER");
        FILE* pager_stream;
        int i;
        if (pager == NULL) {
                pager = "more";
        pager_stream = popen(pager, "w");
        if (pager_stream == NULL)
                err(EXIT_FAILURE, "popen");

        for (i = 0; i < NLINES; ++i) {
                fprintf(pager_stream, "Hello, World %d\n", i);


        return 0;


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Find/grep command to find matching files, print filename, then print matching content stefanlasiewski Programming 9 06-30-2016 05:30 PM
Openwriter : how to print 2 pages on the same A4 ? tulear Mandriva 2 08-13-2005 10:33 AM
How to print Man Pages anindyanuri Linux - Software 8 05-13-2005 09:38 PM
Print text file in html pages ariana Programming 1 11-12-2004 03:18 PM
How to print man pages? fclifton Linux - Newbie 3 09-25-2004 06:33 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:16 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration