C Language Settings console background color and foreground color __c language

Source: Internet
Author: User
Tags rand
#include <stdlib.h>
int main ()
{
System ("COLOR 3 a");
System ("pause");
return 0;
}
Explain the color behind 3 is the background color code A is the front color code, you can change according to these codes

0= Black
1= Blue
2= Green
3= Lake Blue
4= Red
5= Purple
6= Yellow
7= White
8= Gray
9= Light Blue
A= Light Green
b= Light Green
c= Light Red
d= Lavender
E= Light Yellow

f= Bright White


#include "stdafx.h"

#ifdef WIN32
#include <Windows.h>
#endif

#include <time.h>
# Include <stdlib.h>
#include <string.h>

int _tmain (int argc, _tchar* argv[])
{while
	(1)
	{
		Srand (Time (NULL));
		int _nprecolorflag = rand ()%;
		int _nbackcolorflag = rand ()% 6;
		char _cbackcolorflag;
		Switch (_nbackcolorflag)
		{case
		0:{_cbackcolorflag = ' A ';
		Case 1:{_cbackcolorflag = ' B ';
		Case 2:{_cbackcolorflag = ' C ';
		Case 3:{_cbackcolorflag = ' D ';
		Case 4:{_cbackcolorflag = ' E ';
		Case 5:{_cbackcolorflag = ' F '; break;}
		}
		Char strcolorformat[256];
		sprintf (Strcolorformat, "Color  %d%c", _nprecolorflag,_cbackcolorflag);
		System (Strcolorformat); 
		printf ("---------console window color show----------------\ n");
		Sleep (1000);
		System ("CLS");
	}
	return 0;
}





Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.