0

On this page it gives example that to clean the terminal screen I can use printf with \e[1;1H\e[2J

https://stackoverflow.com/a/42500322/4808760

This is the code given there

#ifdef _WIN32
#include <conio.h>
#else
#include <stdio.h>
#define clrscr() printf("\e[1;1H\e[2J")
#endif

I don't understand what is "\e[1;1H\e[2J". Is this whole new thing or just another way of doing format specifier for printf and scanf (can I use it with scanf too)?

What is \e , [1 , ; ,1H , \e and [2J in above string feed for printf in clrscr() macro?

And if I have this code:

int main(){
  printf("Buffered 1\n");
  printf("Buffered 2\n");
  printf("Buffered 3\n");
  clrscr();// Prints to screen
  return 0;
  
}

output:
user:

The problem is with the code in this question clrscr() is that it removes everything from screen. What if I like to remove only printf text Buffered 1\n and Buffered 3\n or whichever possible text from terminal screen. I have also seen in output of programs install in Linux with terminal text. I am using Ubuntu.

halfer
  • 19,824
  • 17
  • 99
  • 186
user786
  • 3,902
  • 4
  • 40
  • 72
  • You should consider that what you saw happening on the screen is an abstraction of what happens in the code. There are multiple ways to achieve the same output and deleting the whole thing and printing just the things you want is the same as deleting only certain things when observed from user perspective. – Uriel.Gi Oct 07 '21 at 10:24
  • 3
    It is a [terminal escape code](https://en.wikipedia.org/wiki/ANSI_escape_code). Don't use it. Just don't clear the screen. If the users want to clear the screen before running your program, they are perfectly capable of doing that themselves. If they do *not* want to clear the screen for whatever reason, then you are providing them a disservice. "What if I like to remove only printf text Buffered 1\n and Buffered 3\n" This is probably a bit more complicated than you would like, but read up on [ncurses](https://en.wikipedia.org/wiki/Ncurses). – n. m. could be an AI Oct 07 '21 at 10:27
  • @n.1.8e9-where's-my-sharem. can u please tell what is `terminal emulator` mentioned in ncurses link u mentioned – user786 Oct 07 '21 at 10:52
  • a terminal emulator is a program that emulates a [glass terminal](https://en.wikipedia.org/wiki/Computer_terminal), something very similar to a windows console. – n. m. could be an AI Oct 07 '21 at 11:45

0 Answers0