问题
I'd recently created this program that displays the last letter of a string. Using this code:
#include<conio.h>
#include<string.h>
#include<stdio.h>
void main()
{
clrscr();
char text[255];
int length= strlen(text);
char lastchar=text[length-1];
gets(text);
cout<<lastchar;
getch();
}
If I use textattribute
or textcolor+128
and change cout
to cprintf(lastchar)
I receive an error which says:
cannot convert int to const* char" and "type mismatch in parameter '___format' in call to 'cprintf(const char*,....)'
回答1:
This is what you are looking for:
//---------------------------------------------------------------------------
#include<conio.h>
//---------------------------------------------------------------------------
#pragma argsused
int main(int argc, char* argv[])
{
for (int i=32;i<256;i++)
{
textcolor(i);
cprintf("%c",i);
}
getch();
return 0;
}
//---------------------------------------------------------------------------
the colors are set with:
textattr(full_attribute);
textcolor(font_color);
textbackground(background_color);
The blinking does not work on my console (Win7) so if you got the same problem you need to animate your self try this:
//---------------------------------------------------------------------------
#include<conio.h>
#include<dos.h>
//---------------------------------------------------------------------------
#pragma argsused
int main(int argc, char* argv[])
{
char *txt="text\0";
_setcursortype(0); // hide cursor
for (;;)
{
gotoxy(1,1); // print position
textattr(7); // white on black
cprintf("%s",txt);
sleep(1); // wait 1 sec
gotoxy(1,1); // print position
textattr(0); // black on black
cprintf("%s",txt);
sleep(1);
if (kbhit()) { getch(); break; } // stop on any key hit
}
// restore console properties
textattr(7);
_setcursortype(1);
return 0;
}
//---------------------------------------------------------------------------
回答2:
You can use textcolor(); 128 code is blink code in turboc++
#include<conio.h>
#include<stdio.h>
int main(){
clrscr();
textcolor(128+6); // or textcolor(134) [128:blinking and 6:brown color]
cprintf("My name is Prashant");
getch(); }
for more help right click on turboC++ window and type textcolor();
来源:https://stackoverflow.com/questions/36590805/how-to-make-the-last-letter-blink