1

I'm trying to make a simple 16*16 terminal display for a C project that uses something like this loop:

for(i = 1; i <= 256; i++) {
    printf("%c ", output[i-1]);
    if(i % 16 == 0) {
        printf("\n");
    }
}

To display something like this (but twice as big):

* * * * * * * *
* * * * * * * *
* * * * * * * *
* * * * * * * *
* * * * * * * *
* * * * * * * *
* * * * * * * *
* * * * * * * *

The problem is, this obviously just prints a new display below the previous one each time the display is refreshed, when I need to print over it instead. The carriage return \r only writes over the previous line, while I need to write over the previous 16.

Is there any way to do this in C? I'm using Windows so I don't know if ncurses is an option.

Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328
  • You probably want to work with the actual *terminal*, not just the opaque standard output stream. Terminal control is platform-specific, so consult your vendor documentation (Windows, I suppose). See also https://stackoverflow.com/questions/138153/is-ncurses-available-for-windows. – Kerrek SB Jan 08 '17 at 03:45
  • Thanks for the advice, I found a solution. – parallel_resistance Jan 08 '17 at 03:50
  • 1
    If the Windows console support ANSI escape codes, you can look at the source code pointed to by [this question](http://stackoverflow.com/q/41485511/2564301) - it positions the cursor at the top of the screen without clearing it first. – Jongware Jan 08 '17 at 12:00

2 Answers2

0

You need to use a library that can handle terminals. One such library is ncurses

Ed Heal
  • 59,252
  • 17
  • 87
  • 127
-2

Okay I got it: on windows system("cls") clears the terminal. It clears all of it instead of just 16 lines, but it does the job.