Use the C language to output color-coded text on the Win console.

Source: Internet
Author: User

Use the C language to output color-coded text on the Win console.

After learning the C language for so long, I have been stuck at the level of compiling the "console" program. However, black windows and white texts are boring. However, as a hobbyist, I don't have much time and energy to learn how to write window programs, nor do I have to use C to call a bunch of APIs to write them. After all, "console programs" can also be colorful.

If you don't talk much about it, go directly to the Code:

# Include <conio. h> # include <stdio. h> # include <windows. h> int main (int argc, char * argv []) {HANDLE hOut; hOut = GetStdHandle (STD_OUTPUT_HANDLE); int I; for (I = 1; I <255; I ++) {SetConsoleTextAttribute (hOut, I); printf ("% 3d \ t", I) ;}printf ("\ n"); SetConsoleTextAttribute (hOut, 0x0007); printf ("demo ended"); getch (); return 0 ;}

For me who are not good at English, I remember the functions, commands, and APIs. In fact, I typed a letter and a letter on the keyboard ......

Related Article

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.