c语言中 gotoxy() 函数的使用

转自  https://blog.csdn.net/radjedef/article/details/79028329windows

#include <stdio.h>
#include <windows.h>
void gotoxy(int x, int y) {
    COORD pos = {x,y};
    HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);// 获取标准输出设备句柄
    SetConsoleCursorPosition(hOut, pos);//两个参数分别是指定哪一个窗体,具体位置
}

int main() {
    int x,y;
    gotoxy(2,2);
    printf("hello,world!");
    system("pause");
    return 0;
}

其实我在是在须要的时候才用的它,写这个也是为了让看到这篇文章的朋友在没必要深刻了解它的前提下,可使用gotoxy();.net

引用百度文库中对coord的解释说: 
COORD是Windows API中定义的一种结构,表示一个字符在控制台屏幕上的坐标。其定义为:code

typedef struct _COORD {
SHORT X; // horizontal coordinate
SHORT Y; // vertical coordinate
} COORD;
  • x,y就是在使用gotoxy后光标所在的位置 ,然后面的两句
HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
    SetConsoleCursorPosition(hOut, pos);