Thread: function similar to gotoxy()

  1. #1
    Registered User
    Join Date
    Aug 2011
    Posts
    385

    function similar to gotoxy()

    Is there any function similar to gotoxy that places the cursor at a desired position on the screen?

    gotoxy in c

  2. #2
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Yes, in Windows it's SetConsoleCursorPosition(), and you need to include windows.h in your program.

    Are you using Windows?

  3. #3
    Registered User
    Join Date
    Dec 2011
    Posts
    795
    Quote Originally Posted by Adak View Post
    Yes, in Windows it's SetConsoleCursorPosition(), and you need to include windows.h in your program.
    That's for console cursor position. If you were looking for how to actually move the mouse around the screen, you could try something like the X11 library..

  4. #4
    Registered User
    Join Date
    Mar 2011
    Posts
    546
    thats an OS/platform dependent function and not in the standard C library. you have to tell us at least what OS you are using and if you are using the console or a windowing system.

  5. #5
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    This is an example of using the Windows API version, of gotoxy() in conio.h.

    Code:
    
    #include <windows.h>     //for older compilers, don't include this line
    #include <stdio.h>
    #include <time.h>
    #define gotoxy Gotoxy    // "    "     "         "       "     "    "
    
    void Gotoxy(int x, int y);
    
    int main() {
       FILE *fp=NULL;
       int i, j;
       char choice[3];
       char ch='\0';
       for(i=0; i< 10; i++)
          printf("\n\n\n\n\n");
       do {
          choice[0]='\0';
          for(i=3; i< 21; i++) {
             Gotoxy(1,i);
             printf("                                                                    ");  
          }
          Gotoxy(1,3);
          printf("\t\t       Welcome to Sudoku EZ Solver's Main Menu\n\n");
          printf("    *press 'b' to benchmark this program\n\n");
          printf("    *press 'l' to load a puzzle from this program\n\n"); 
          printf("    *press 'e' to enter your own puzzle, or 'q' to quit [b/l/e/q]: "); 
          for(i=0; i < 9; i++) {
             for(j = 0; j < 9; j++) {
                grid[i][j] = 0;
             }
          }
          fgets(choice, sizeof(choice),stdin);
          if(strlen(choice) < 2)
             continue;
          if(choice[0] >= 'a' && choice[0] <='z')
             ch=choice[0]; 
          if(ch == 'q') 
             break;
          for(i=3; i< 10; i++) {
             Gotoxy(1,i);
             printf("                                                                    ");  
          }
       }while(ch != 'q');
    
       printf("\n");
      return 0;
    }
    
    // Include this function, for newer compilers
    void Gotoxy(int x, int y) {
      COORD coord;
      coord.X = x;
      coord.Y = y;
      SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
    }
    Last edited by Adak; 12-25-2011 at 02:10 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. function similar to execvp()
    By Elkvis in forum Linux Programming
    Replies: 10
    Last Post: 09-22-2011, 11:25 AM
  2. Replies: 3
    Last Post: 08-14-2011, 12:38 PM
  3. function similar to strpos() ?
    By willc0de4food in forum C Programming
    Replies: 18
    Last Post: 10-08-2005, 04:13 PM
  4. gotoxy function
    By brandonp in forum C Programming
    Replies: 4
    Last Post: 02-21-2002, 07:13 AM
  5. gotoxy(x, y); function
    By bluehead in forum Windows Programming
    Replies: 8
    Last Post: 01-13-2002, 01:08 PM