我的第一个有颜色的控制台C程序
首先给大家列出我程序所使用的重要三个函数原型 背景颜色:void textbackground(int color);
设置字符颜色:void textcolor(int color);
gotoxy函数:void gotoxy(int x, int y);
代码:
程序代码:#include "conio.h"
#include "stdio.h"
main()
{ char a[100],ch=0;
int i=0,b; int x=10,y=10;
char _i=20;
clrscr();
textbackground(0);
textcolor(2); /*设置字体颜色*/
printf("我的博客:BLOG.\n请输入一些字符:\n");
/* scanf("%s",a);*/
for(a[ch]=getchar();a[ch]!='\n';a[++ch]=getchar());
a[ch]='\0';
textcolor(4);
if(strlen(a)>20)
{
printf("error");
getchar();
getchar();
exit();
}
for(b=0;b<5;b++) /*打印出一个红色方框*/
{
if(b==0||b==4)
{ gotoxy(x,y++);
textbackground(4);
cprintf("+--------------------+\n");
}
else
{
gotoxy(x,y++);
textbackground(4);
cprintf("|");
while(i++<20)
{
textbackground(7);
cprintf(" ");
}
i=0;
textbackground(0);
gotoxy(x+21,y-1);
textbackground(4);
cprintf("|");
}
}
gotoxy(20/2-strlen(a)/2+11,12); /*将输入的字符在方框中永远居中输出*/
_i=8;
while(i<strlen(a))
{
textcolor(_i++);
textbackground(_i);
cprintf("%c",a[i++]);
}
gotoxy(1,1);
getchar();
/* getchar();*/
/* getchar();*/
}
本人第一个有颜色的C语言程序,欢迎交流哦!QQ:974740928
大牛勿喷。







新手上路,多多交流!
