Advertisement
Megaerikivan

Gotoxy

Jan 30th, 2017
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.74 KB | None | 0 0
  1. #ifdef __unix__
  2.  
  3. void gotoxy(short x,short y){
  4.         printf("%c[%d;%df",0x1B,y,x);
  5. }
  6.  
  7. #elif defined(_WIN32) || defined(_WIN64)
  8. #include <stdlib.h>
  9. #include <windows.h>
  10. short gotoxy(short x, short y)
  11. {
  12.    COORD coord;
  13.    CONSOLE_SCREEN_BUFFER_INFO csb;
  14.    HANDLE h_stdout;
  15.  
  16.    if ((h_stdout = GetStdHandle(STD_OUTPUT_HANDLE)) == INVALID_HANDLE_VALUE)
  17.       return 0;
  18.    if (GetConsoleScreenBufferInfo(h_stdout, &csb) == 0)
  19.       return 0;
  20.  
  21.    x--;
  22.    y--;
  23.    if (x < csb.srWindow.Left || x > csb.srWindow.Right)
  24.       return 0;
  25.    if (y < csb.srWindow.Top || y > csb.srWindow.Bottom)
  26.       return 0;
  27.  
  28.    coord.X = x;
  29.    coord.Y = y;
  30.    if (SetConsoleCursorPosition(h_stdout, coord) == 0)
  31.       return 0;
  32. }
  33.  
  34. #endif // defined
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement