Search code examples
turbo-c++turbo-c

How to make the last letter blink?


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*,....)'

Solution

  • 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;
        }
    //---------------------------------------------------------------------------