LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices

Reply
 
Search this Thread
Old 03-25-2004, 08:29 PM   #1
akin81
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
aluser
Member
 
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

Code:
#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);
        }

        pclose(pager_stream);

        return 0;
}
 
  


Reply


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 8 12-18-2013 05:36 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


All times are GMT -5. The time now is 11:17 PM.

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