怎样使c语言中运行界面的光标移至上一行?

来源:百度知道 编辑:UC知道 时间:2024/06/27 19:09:56

turboc的

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

int main()
{
int x, y;

gotoxy(5, 5);
printf("position: 5, 5");
x = wherex();
y = wherey();

getch();
gotoxy(x, y - 1);
getch();

}

控制台的

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

void gotoxy(HANDLE hOut, int x, int y);
void getxy(HANDLE hOut, int &x, int &y);

int main()
{
int x, y;
HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);

gotoxy(hOut, 5, 5);
printf("position: 5, 5");
getxy(hOut, x, y);

getch();
gotoxy(hOut, x, y - 1);
getch();

CloseHandle(hOut);
}

void gotoxy(HANDLE hOut, int x, int y)
{
COORD pos;
pos.X = x;
pos.Y = y;
SetConsoleCursorPosition(hOut, pos);
}

void getxy(HANDL