wherex() and wherey() functions of conio.h in C

In this article, we are going to learn about the use of wherex() and wherey() functions of conio.h header file for getting the position of cursor.
Submitted by Manu Jemini, on March 15, 2018

<conio.h> - wherex() and wherey() functions

These two functions are similar in nature. As they tell the position of the cursor, the only difference is that the wherex() function gives the co-ordinate of X-axis, on the other hand, wherey() function gives the co-ordinate of Y-axis.

Now as the example below, illustrates that you can easily get and use the co-ordinate of the cursor by calling and storing the integer these functions will return.

This is very useful is making games, as we always want to keep track of the cursor.

These functions are from the conio.h file and you should include them in your program.

wherex() and wherey() functions Examples

wherex() function Example in C

#include <stdio.h>
// to use 'wherex()'
#include <conio.h>

main() {
  // defining the type of variable
  int a;

  // printing the message
  printf("Includehelp\n\n");

  // getting the position of cursor
  a = wherex();

  // printing the position of cursor
  printf("Prosition of cursor on x axis after printing the message = %d\n", a);

  getch();
  return 0;
}

Output

conio.h - wherex() function Example in C

wherey() function Example in C

#include <stdio.h>
// to use 'textcolor()'
#include <conio.h>

int main() {
  // set the color of text
  textcolor(BLUE);
  // message
  cprintf("Color of text is BLUE\n\n");

  // set blinking color
  textcolor(GREEN + BLINK);
  // message
  cprintf("\nThis is BLINKING text");

  getch();

  return 0;
}

Output

conio.h - wherey() function Example in C



Comments and Discussions!

Load comments ↻






Copyright © 2024 www.includehelp.com. All rights reserved.