+ 2

How to change background colour in c programming ?

Please help me. If you know then please reply it . And please write the full code to colour background.

24th Sep 2018, 1:53 AM
Kritikumar Behera
Kritikumar Behera - avatar
3 Answers
+ 3
This ANSI escape sequence worked for me in my Android terminal*: #include <cstdio> int main() { // 42 = green bg printf("%c[%dmHELLO!\n", 0x1B, 42); } More information on ANSI escape sequences for color here: https://stackoverflow.com/questions/4842424/list-of-ansi-color-escape-sequences * [meta] g++ or possibly cppDroid can be used on Android to compile local codes.
24th Sep 2018, 2:12 AM
Kirk Schafer
Kirk Schafer - avatar
+ 2
Kritikumar Behera [meta / lost knowledge / skippable] You can write directly to video memory at 0xB800:0000 (the text mode video buffer start address). The bytes are laid out as text-then-color (or the opposite, I forget), and there's a discussion here: https://forum.osdev.org/viewtopic.php?f=1&t=16333 and some direct-write code here (I think it writes random colors): https://gist.github.com/manuj10/3423732 Probably comment line 23 (the shutdown) Please don't worry too much about it if you want an easier way; this is only for future reference if you are spending research time / serious play. edit: More info on CPU mode and addressing the buffer: https://stackoverflow.com/questions/32972051/in-c-how-do-i-write-to-a-particular-memory-location-e-g-video-memory-b800-in
24th Sep 2018, 4:08 AM
Kirk Schafer
Kirk Schafer - avatar
0
In the first code The function says error . I use turbo c/c++. In the 4th line of program the error says illigal function.
24th Sep 2018, 3:16 AM
Kritikumar Behera
Kritikumar Behera - avatar