C Language and Libraries Help (clang.hlp) (Table of Contents; Topic list)
Important Notice
The pages on this site contain documentation for very old MS-DOS software, purely for historical purposes. If you're looking for up-to-date documentation, particularly for programming, you should not rely on the information found here, as it will be woefully out of date.
MORE.C
                                             Up Contents Index Back
─────Run-Time Library───────────────────────────────────────────────────────
 
/* MORE.C illustrates line input and output using:
 *      gets            puts            _isatty          _fileno
 *
 * Like the DOS MORE command, it is a filter whose input and output can
 * be redirected.
 *
 * By default, this program is built for DOS.
 */
 
#include <stdio.h>
#include <io.h>
#include <bios.h>
 
void main()
{
    long line = 0, page = 0;
    char tmp[128];
 
    /* Get each line from standard input and write to standard output.   */
    while( 1 )
    {
        /* If standard output is screen, wait for key after each screen. */
        if( _isatty( _fileno( stdout ) ) )
        {
            /* Wait for key every 23 lines.  */
            if( !(++line % 23 ) )
                _bios_keybrd( _KEYBRD_READ );
        }
        /* Must be redirected to file, so send a header every 58 lines.  */
        else
        {
            if( !(line++ % 58) )
                printf( "\f\nPage: %d\n\n", ++page );
        }
 
        /* Get and put a line of text. Note that NULL return indicates
         * error or end-of-file. For this program, we don't care which.
         */
        if( gets( tmp ) == NULL )
            break;
        puts( tmp );
 
    }
}
                                    -♦-