Probably the easiest way is to set the background color of your text using ANSI:
For example, using:
echo -e "\e[37m\e[41m"
will give you blue text on a red background (you can use it to check the effect in bright, easily distinguishable colors).
While
echo -e "\e[97m\e[40m"
sets the foreground to white and the background to black for the duration of your program.
If you find yourself getting a kind of ugly transition zone between the background color and the terminal, just print enough lines of a new line to erase the entire screen.
To use this in C, you obviously need printf instead of echo .
The ANSI escape codes wiki page contains additional information.
source share