How to change cursor style using C

In this article, we will discuss how to change the cursor style on the screen in C.

Approach: The idea is to use the setcursortype() function to change the cursor style on the output screen. This function takes cursor-type as an argument and is declared under the conio.h header file.

Header File:

#include <conio.h>

Below are the list of valid cursor-type:

  1. _NOCURSOR: Turns off the cursor.
  2. _NORMALCURSOR: Normal underscore cursor.
  3. _SOLIDCURSOR: Solid block cursor.

Syntax:



void _setcursortype(int cursor-type)

Program 1:

Below is the program for changing the cursor type to _NOCURSOR:

filter_none

edit
close

play_arrow

link
brightness_4
code

// C program to change cursor style
#include <conio.h>
#include <stdio.h>
  
// Driver Code
int main()
{
    // Call _setcursortype function
    _setcursortype(_NOCURSOR);
  
    // Print message
    cprintf("No Cursor    :");
    return 0;
}
chevron_right


Output:
Below is the output of the above program:

Program 2:

Below is the program for changing the cursor type to _SOLIDCURSOR:

filter_none

edit
close

play_arrow

link
brightness_4
code

// C program to change cursor style
#include <conio.h>
#include <stdio.h>
  
// Driver Code
int main()
{
    // Call _setcursortype function
    _setcursortype(_SOLIDCURSOR);
  
    // Print message
    cprintf("Solid Cursor    :");
    return 0;
}
chevron_right


Output:
Below is the output of the above program:

Program 3:

Below is the program for changing the cursor type to _NORMALCURSOR:

filter_none

edit
close

play_arrow

link
brightness_4
code

// C program to change cursor style
#include <conio.h>
#include <stdio.h>
  
// Driver Code
int main()
{
    // Call _setcursortype function
    _setcursortype(_NORMALCURSOR);
  
    // Print message
    cprintf("Normal Cursor :");
  
    return 0;
}
chevron_right


Output:
Below is the output of the above program:




Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :