Search code examples
ccursor-position

Cursor positioning in Terminal using C program


My program will open a file and print the contents in the terminal. As the file is large, the terminal goes two or more page. I'll have to slide up to the first line of the file to read from the beginning. Is it possible using C program?

void hfile()
{
printf("\033[2J");
printf("\033[0;0H");
FILE *ffp;
char c;

ffp=fopen("help.txt","r");
while((c=getc(ffp))!=EOF)
    printf("%c",c);

}

Solution

  • Not via stdlib. You will have to use some third-party library like ncurses.