In a C program if a lot of text is output at once then a screen may not have enough space to show it all and some of the information may be missed by the user.
How can I enable a user to control the scrolling to read such output?
In a C program if a lot of text is output at once then a screen may not have enough space to show it all and some of the information may be missed by the user.
How can I enable a user to control the scrolling to read such output?
@Veltas, is correct, there's no portable means or even assumptions that you can make that always get this right. Usually you spew your output and let the caller decide what to do with it (piple & filter model). They may decide to redirect it to a file, terminal or filter. Common desktop OS's have utilities for dealing with the spew (tee, more, less, findstr, grep, etc), but sometimes you want your application to be more interactive, perhaps you need them to read and then respond to that output? Your options then are to use a configuration file or command line parameters and "reasonable defaults" for the display devices height and width. Using those, you can count how many lines you're spewing and stop short of scrolling the view port.
There are nuances to consider. How to handle lines that are longer than the view port is wide? It's common to just let the display wrap the line and count that output as multiple lines, but you have to do some math and you can't be sure the display actually does line wrapping. Then there's whether to wrap only at word boundaries or break words when you wrap, which ANSI escape codes are available, if any? There's actually many attributes to consider.
Fortunately, there are more or less portable terminal/display libraries you can use that cover most of the common OS console environments.
I am sure there are others my addled brain can't recall at the moment.