1

So I am working on this side project game kinda thing, and I want to put it inside of a border/box. I then want to print text constantly inside that border: adding text, removing it, changing it etc. I've looked far and wide, and cannot find anyway to print inside the box separately from the actual box.

My current implementation is to clear screen, and then reprint the entire box with new text using this:

 printf("\e[1;1H\e[2J");

The issue with this is that I get this very obnoxious blinking effect, because every iteration of clearing my screen causes that portion of the screen to become black for a certain period of time.

So I am looking for a few solutions.

  1. How to print a border separate from the print statement inside of it. I currently am implementing it like such:

          printf("| |                        Hello There                     ||\n");
    

    , and then repeating that all the way down to make a border.

  2. How to completely overwrite the already outputted text so that this blinking effect can go away. So imagine \r removing a line, I want something like that, that removes the whole text and replaces it with a new set of text
  3. How to change the location of where the user inputs into the console, so you can type into a box

Those are basically the only solutions I could think of, if you have any others I'd love to hear them

I also had a general question about c.

conio.h, graphics.h, windows.h and a few other headers don't work for my compilers. I use ubuntu, and they always come up with some error saying I can't use them. I appreciate someone explaining this to me.

Please let me know what you think, and if you need more info, I'll be sure to provide it

-Ryan

genpfault
  • 51,148
  • 11
  • 85
  • 139
Ryan Keough
  • 121
  • 1
  • 8
  • 2
    You are still using the ancient Borland Turbo C++? I would prepare the new screen contents in a buffer, with full lines (padded with spaces), then `gotoxy` to the top corner, then output the buffer contents in one call. Or if it's just a part of the screen, write a series of strings positioned with `gotoxy`. Don't blank it first, just overwrite what was there. – Weather Vane Feb 12 '20 at 16:15
  • 3
    For Linux you want to use the "ncurses" library – user253751 Feb 12 '20 at 16:19
  • 3
    @ReticulatedSpline `graphics.h` is Borland, along with the other two. Methinks a serious tools update is needed. – Weather Vane Feb 12 '20 at 16:20

2 Answers2

3

conio.h and windows.h are not standard Linux libraries, so they won't compile on Linux unless you install extra software. One solution would be to use a library designed for managing the screen like ncurses.

0

You can do that with loops and ASCII characters similar like that:

#include <stdio.h>

int main()
{
int i;
printf("\n\t\t═");
for(i=0;i<=20;i++)
{
    printf("═");

}

for(i=0;i<=22;i++)
{
printf("\t\t║\n");
if(i==10)
{
    printf("\t\t\tHello There \t\n");
}
printf("\t\t\t\t\t║\n"); 
}

printf("\t\t═");
for(i=0;i<=22;i++)
{
    printf("═");

}


return 0;
}
  • Thank you for your feedback, but this isn't what I am looking for. I am trying to make a box that surrounds my text that won't be interrupted by the text forming in the middle. I am planning to use usleep() to slow down how each letter of a string comes out, however this will impact how the box characters will come out because they won't print until the print statement before it has executed – Ryan Keough Feb 18 '20 at 17:57