【C语言】在VC中使用gotoxy函数实现光标的移动

#include <stdio.h>
#include <conio.h>
#include <windows.h>

void gotoxy(int x, int y)
{
    COORD coord = {x, y};   
    /*COORD是Windows API中定义的一种结构,表示一个字符在控制台屏幕上的坐标。其定义为:

    typedef struct _COORD {

    SHORT X; // horizontal coordinate

    SHORT Y; // vertical coordinate
    } COORD;*/

    SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
}


int main(int argc,char *argv[])
{
    gotoxy(5,5);
    printf("hello!
"); 
    return 0;
}
原文地址:https://www.cnblogs.com/laohaozi/p/12538202.html