C语言实现Press any key to change color, do you want to try it. Please hurry up!
时间: 2024-04-13 10:30:46 浏览: 170
【德意志银行-2024研报】Asia Economic Notes Singapore No hurry to ease.pdf
Sure, I'd be happy to show you how to implement that in C language. Here's a simple example:
```c
#include <stdio.h>
#include <conio.h>
int main() {
printf("Press any key to change color\n");
getch(); // Wait for a key press
system("color 0A"); // Change console color to bright green
return 0;
}
```
In this example, we use the `conio.h` header file to access the `getch()` function, which waits for a key press. Once any key is pressed, we use the `system()` function to execute the command `color 0A`, which changes the console color to bright green (0 for background, A for text).
Please note that this code works only on Windows platforms. If you're using a different operating system, let me know, and I can provide an alternative solution.
阅读全文