定义color函数,到时直接调用
#include<stdio.h>
#include<time.h>
#include<windows.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<process.h>
#include<conio.h>
#include <dir.h>
#include<ctype.h>//调用这么多函数是个人习惯
void color(const unsigned short color1)
{
if(color1>=0&&color1<=150)
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), color1);
else
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 7);
}
int main() {
color(13);
printf("He");
color(14);
printf("ll");
color(9);
printf("o ");
color(10);
printf("wo");
color(11);
printf("rl");
color(12);
printf("d!\n");
Sleep(5000);
return 0;
}
当然,你还可以换其他颜色,只要改color()中的数字就可以了。