Use of more in C program

[hr]I am writing a fairly complex command-line program in C for DOS. In a few words, it involves several menus, user-entered data, writing to and reading from a disk file, and output to screen of data coming from sort routines.

The output is usually several screens long, but I haven't been able to figure out how to get just one screen of output at a time. I've tried every way I can think of to use the DOS [blue]more[/blue] command, namely:

1) command-line argument [blue]more < filename[/blue].
2) command-line argument [blue]filename | more[/blue].
3) including it at various points in the C source file as [blue]system("more")[/blue].

The result is simply that program execution stops. Can what I want be done with [blue]more[/blue], or is there some C function that I should be using instead?[hr]


  • Count the number of lines written to the screen and call getche() when the max number of lines written is reached.
  • On the DOS command line the filenames following '<', '>' or '|' are not command parameters. They are never seen by the program or command about to be launched. The executable probably from the Windows or Windowscommand directory, also named command interpreter, identifies these special character and the files after, and redirects the keyboard input and/or screen output from/to the named files.
    At least in DOS 7.0 (cames with Win95) the [b]MORE[/b] command can directly take a file as argument (no need for '<' or '|' characters) which is paged on screen. If no argument to the [b]MORE[/b] command is given, [b]MORE[/b] reads and pages "standard input" which is keyboard. This is what makes it page files with commands like [b]MORE < file.txt[/b].
    Your program stops because [b]MORE[/b] is reading the keybord (for the usual scope of pageing). Just pres [b]Ctrl+Z[/b] (End Of File).
    To have [b]MORE[/b] page your file you should send the [b]MORE < file.txt[/b] command to the itself (or try [b]MORE file.txt[/b]. To launch you should use the path from the environment variable [b]COMSPEC[/b] or just [b]COMSPEC[/b] if it includes the filename (check it for yourself). Exec a command line like [code]%COMSPEC%[command] more < file.txt[/code] Or you can try [code]system("MORE < file.txt");[/code]
    Also note that useing [b]MORE[/b] instead of Stober's suggenstion requires you to have your file.txt entirely generated at the output time.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!