How to use gotoxy() in codeblocks?
The gotoxy() function places the cursor at the desired location on the screen. This means it is possible to change the cursor location on the screen using the gotoxy() function. It is basically used to print text wherever the cursor is moved. Below is the C program to print the “hello” message on the screen without using the gotoxy() function:
Explanation: The message “hello” is print on the top left side of the screen by default. So to print text at a particular coordinate use the gotoxy() function.
gotoxy() In Code::Blocks:
Code blocks don’t have a gotoxy() predefined function. Therefore, “SetConsoleCursorPosition()” can be used to carry out the same procedure. To use this function add a header file called #include<windows.h>. The arguments for SetConsoleCursorPosition() are:
- Handle: To get the value of handle, call a predefined function “GetStdHandle(STD_OUTPUT_HANDLE)”.
- Coord: The predefined function used to get X and Y coordinates.
Note: A screen has 25 lines and 80 columns.
Below is the implementation of the above-discussed function to print the “hello” message in the center of the screen:
Note: Any value for X and Y can be used to print the desired text at any location on the screen. Here, X is used for the vertical axis and Y is used for the horizontal axis.