[C / C ] Gotoxy() 在开发-C – Gotoxy在开发-C

在开发-C ++默认的无功能gotoxy(X, 和). 我们需要使用库来构建它 WINDOWS.H 如下:

void gotoxy(int x, int y)
{
  static HANDLE h = NULL;  
  if(!h)
    h = GetStdHandle(STD_OUTPUT_HANDLE);
  COORD c = { x, y };  
  SetConsoleCursorPosition(h,c);
}

首席执行官:

#include <stdio.h>
#include <windows.h>
void gotoxy(int x, int y)
{
	static HANDLE h = NULL;  
	if(!h)
		h = GetStdHandle(STD_OUTPUT_HANDLE);
	COORD c = { x, y };  
	SetConsoleCursorPosition(h,c);
}
int main(){
	char *s = "nguyenvanquan7826";
	gotoxy(40 - strlen(s)/2, 1);
	printf("%snn", s);
}

gotoxy在开发 -  C