How to make the last letter blink?

别来无恙 提交于 2019-12-04 07:02:04

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!