Search code examples
ctimecursor

How to disable the blinking cursor in the output window if i m using turbo cpp compiler?


I made a simple program to show the current date and time using some standard functions in turbo cpp.I want to know how can I turn of the blinking cursor from the output window. My current code is as follow :

#include<conio.h>
#include<stdio.h>
#include<time.h>

void main()
{
   time_t t;
   printf("Day and time \n\n");
   while(1)
   {
      time(&t);
      clrscr();
      printf("Day and time is \n%s",ctime(&t));
      delay(1000);

      if(kbhit())
          break;//breaks the infinite loop if any key is hit
  }

  getch();

}

Solution

  • Solution to your problem is _setcursortype() function.

    Ques. What is _setcursortype() function and what functionality it provides to you?

    Ans- first, setcursortype() function is not ANSI/ISO C standard function. second, It is defined in conio.h and provided with old compilers(like turbo c) and obviously not portable.

    I explain all Functionalities provided by _setcursortype() in a simple c code. And this code runs on my turboc so I hope it'll definately run on your own. :)

    #include<stdio.h>
    #iclude<conio.h> 
    
    int main()
    {
    
    printf("Normal Cursor: "); getch();          /* Display the normal cursor */
    
    
    _setcursortype(_NOCURSOR);
    printf("No Cursor : "); getch();              /* Turn off the cursor */
    
    
    _setcursortype(_SOLIDCURSOR);       
    printf("Solid Cursor : "); getch();          /* Switch to a solid cursor */
    
    
    _setcursortype(_NORMALCURSOR);         
    printf("Normal Cursor: "); getch();          /* Switch back to the normal cursor */
    
    return 0;
    getch();
    }
    

    It also helps you to how to turn off or disable blinking cursor on console window of your turbo c.:)