Use the system function to personalize screen display, and the system function Screen Display

Source: Internet
Author: User

Use the system function to personalize screen display, and the system function Screen Display
Function Name: system function: the method used to issue a doscommand: system ("doscommand"); (the system function must be followed by a header file <stdlib. h> .) Using the system function, you can customize the display in the screen of the console program. The following describes the usage:

1. system ("color Parameters ")

Change the background color and text color of the screen window.

The color attribute is specified by two hexadecimal numbers-the first is the background color and the second is the text color. Each number can be one of the following values:

0 = black
1 = blue
2 = green
3 = light green
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 = pale yellow
F = bright white

For example, to add the code system ("color 9F"), you can set the background color of the screen window to blue and the text color to white.

1 # include <stdio. h> 2 # include <stdlib. h> 3 4 int main (int argc, char * argv []) 5 {6 system ("color 9F"); 7 printf ("My C language program! \ N "); 8 return 0; 9}

Program running window:

Note: (1) if only one parameter is specified, only the background color is set. For example: system ("color 9"), the background color is blue, and the text color remains unchanged.

(2) If no parameter is specified, such as system ("color"), this command restores the color to the default color when CMD. EXE is started.

Ii. system ("pause") when most IDE tools compile C language programs, system ("pause") is automatically added to the end of the main function, so that the program running can be suspended, this allows you to observe program execution results on the screen. However, some IDE tools do not automatically add this statement. After compilation and running, the screen window will flash and close automatically, so it is too late to view the program running result, in this case, you need to add this statement to the main function.
1 # include <stdio. h> 2 # include <stdlib. h> 3 int main (int argc, char * argv []) 4 {5 printf ("My C language program! \ N "); 6 system (" pause "); 7 return 0; 8}

After the running result is displayed, press any key to continue...

If you do not want to display a prompt, you can use the output redirection command to change the code of line 6th:

system("pause >nul");

In this way, the prompt "press any key to continue..." is no longer displayed on the screen. Note that it is nul, not null.

Greater than>, which means to redirect the command output to other devices such as files and printers.

Nul is a virtual empty device in DOS. "> Nul" indicates to redirect the screen display information generated by the Command (>) to the virtual null device (nul), so that the execution result of the pause command is not displayed on the screen.

Iii. system ("cls ")

Clear screen information. When you need to clear the displayed information in the compilation process, for example, you need to repeatedly enter the student information. After the first student's information is recorded, you want to clear the information and then enter the second student information, this statement will be used in this case.

 

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.