Learning TOS Scroll With Pads in C Program

How to write a C Program Learning TOS Scroll With Pads in C Programming Language ?


Solution:

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


#define FILENAME "df.txt"
WINDOW *spare;
WINDOW *prnt;

int counter = 1;

void Drawscreen()
{
    clear();
    box(stdscr, ACS_VLINE, ACS_HLINE);
    refresh();


   
    //prnt = newpad(22, 80);
    prnt = newpad(1000, 82);
    wrefresh(prnt);
    scrollok(prnt, TRUE);
   


}


int readfile()
{
        FILE *fp = fopen(FILENAME, "r");

        if(fp == NULL) {
        return(1);
    }
   
        char line[1024];
       
       
   
        while(fgets(line, 1024, fp) ) {
        //while((fgets(line, 2048,     fp) ) != EOF) {
        mvwprintw(prnt, counter, 2, "%s", line);
        //prefresh(prnt, 1,1,3,2,23,77);
        prefresh(prnt, 1,1,3,2,23,82);
        ++counter;
        wmove(prnt, counter, 2);
        }
   
    return 0;
}




int main()
{
    int key;
    initscr();
    noecho();

   

   
       
       
        Drawscreen();
        readfile();
       
       
   
   
   
   
   
/* Scrolling */
    key = getch();
    wscrl(prnt, 3);
    prefresh(prnt, 1,1,3,2,23,82);

    getch();
   
    wscrl(prnt, 10);
    prefresh(prnt, 1,1,3,2,23,82);

    getch();

    wscrl(prnt, 15);
    prefresh(prnt, 1,1,3,2,23,82);

    getch();
   
    wscrl(prnt, 25);
    prefresh(prnt, 1,1,3,2,23,82);

    getch();
   
    wscrl(prnt, 30);
    prefresh(prnt, 1,1,3,2,23,82);
   

    getch();
   
    wscrl(prnt, 3);
    prefresh(prnt, 1,1,3,2,23,82);
   

    getch();
   
    wscrl(prnt, 40);
    prefresh(prnt, 1,1,3,2,23,82);
   

    getch();
   
    wscrl(prnt, 3);
    prefresh(prnt, 1,1,3,2,23,82);
   

    getch();
   
    wscrl(prnt, 3);
    prefresh(prnt, 1,1,3,2,23,82);
   

    getch();
   
    wscrl(prnt, 3);
    prefresh(prnt, 1,1,3,2,23,82);
   

    getch();
   
   
    wscrl(prnt, 3);
    prefresh(prnt, 1,1,3,2,23,82);
   

    getch();
   
   
    wscrl(prnt, 3);
    prefresh(prnt, 1,1,3,2,23,82);
   

    getch();
   
   
    wscrl(prnt, 3);
    prefresh(prnt, 1,1,3,2,23,82);
   

    getch();
   
   
   
    wscrl(prnt, 3);
    prefresh(prnt, 1,1,3,2,23,82);
   

    getch();
   
   
    wscrl(prnt, 3);
    prefresh(prnt, 1,1,3,2,23,82);
   

    getch();
   
   
    wscrl(prnt, 3);
    prefresh(prnt, 1,1,3,2,23,82);
   

    getch();
   
   
   
    wscrl(prnt, 3);
    prefresh(prnt, 1,1,3,2,23,82);
   

    getch();
   
   
    wscrl(prnt, 3);
    prefresh(prnt, 1,1,3,2,23,82);
   

    getch();
   
   
    wscrl(prnt, 3);
    prefresh(prnt, 1,1,3,2,23,82);
   

    getch();
   
   
    wscrl(prnt, 100);
    prefresh(prnt, 1,1,3,2,23,82);
   

    getch();
   
    wscrl(prnt, -31);
    prefresh(prnt, 1,1,3,2,23,82);
    getch();
   

    endwin();
   
    printf("Lines Count: %i\n", counter);
   
    return 0;
}


Learn More :