分享C语言printf控制台花样打印,可以彩色显示。 - #include "../0_toolboxfile/myprintf.h" //相关函数的声明
- //#include "../0_toolboxfile/myprintf.c" //相关函数的定义(很少这样做,可能有重定义问题,解决方案:放在同名 myprintf.h 最后面包含)
- int main(void)
- {
- int a,b,c;
- myprintf_setStrFormat(0,0,RED_Char,BLUE_Back); //蓝底红字
- printf("彩色花样打印\n");
- myprintf_setDefault(TRUE); //恢复正常打印
- printf("恢复正常打印\n");
- myprintf_color(YELLOW_Char,BLUE_Back,"y%%dou %c hh%daha",'A',52,87); //蓝底黄字,只用到2个参数
- printf("你好,C语言\n");
- printf("输入2个或以上数字回车:\033[");
- a=getchar()-48;
- scanf("%d",&b);
- c=a*b;
- printf("ans=%d\n",c);
- if(c%2==0)
- getch(); //等待按下任意键,再继续执行下面的语句,在<conin.h>文件里
- else
- system("pause"); //在命令行上输出"按任意键继续..."的文字,按任意键结束,在<windows.h>文件里
- return 0;
- }
复制代码
|