C语言控制台输出指定位置

2025-04-13 18:41:05
推荐回答(2个)
回答(1):

#include 
#include 

int main()
{
    printf("Hello world!\n");
    system("cls");
    printf("2.Hello world!");
    return 0;
}

回答(2):

1.gotoxy函数:
    原型:extern void gotoxy(int x, int y);
    用法:#include
    功能:将光标移动到指定位置说明:gotoxy(x,y)将光标移动到指定行y和列x。设置光标到文本屏幕的指定位置,其中参数x,y为文本屏幕的坐标。
    gotoxy(0,0)将光标移动到屏幕左上角

2.例程(下面这个例子将在屏幕中央输出“hello world”):

    #include 
    int main(){
        clrscr();    //清除屏幕
        gotoxy(35, 12);    //挪动鼠标到屏幕中央
        cputs("Hello world");
        getch();
        return 0;
    }