gotoxy 函数与 C ( linux/unix )

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7581347/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-05 06:24:10  来源:igfitidea点击:

gotoxy function with C ( linux/unix )

clinux

提问by Ilian Zapryanov

I am making a terminal software like GNU MC and I need gotoxy foo, but it has to be in C. It can be in macro or in C, but not in ASM code because I don`t know ASM. Any bit operators can be used too, but I had no idea how to pseudocode it or how to start doing this. Any advice will be most appreciated :)

我正在制作一个像 GNU MC 这样的终端软件,我需要 gotoxy foo,但它必须是 C 语言。它可以是宏或 C 语言,但不能是 ASM 代码,因为我不知道 ASM。也可以使用任何位运算符,但我不知道如何对其进行伪代码或如何开始这样做。任何建议将不胜感激:)

采纳答案by Jurlie

see the ncurses library for such a function

有关此类功能,请参阅 ncurses 库

you need some function from the listed here

您需要此处列出的某些功能

http://tldp.org/HOWTO/NCURSES-Programming-HOWTO/printw.html#PRINTWCLASS

http://tldp.org/HOWTO/NCURSES-Programming-HOWTO/printw.html#PRINTWCLASS

回答by Arafangion

Is this function sufficient?

这个功能够用吗?

void gotoxy(int x, int y)
{
    printf("You are now at position (%d, %d). You"\
           " look around and you see a vast emptiness...", x, y);
}

You do, however, mention that you are using software like GNU MC (Midnight Commander?), so perhaps you actually mean something more like:

但是,您确实提到您正在使用 GNU MC(Midnight Commander?)之类的软件,所以也许您的意思实际上更像是:

void goto_url(char* url) { ... code here... }

回答by niko

Hope this snippet works with you.

希望这个片段对你有用。

I found these snippet on google long ago. I just saved it on my disk, now after seeing your post I just opened it.

我很久以前在谷歌上发现了这些片段。我刚把它保存在我的磁盘上,现在看到你的帖子后我才打开它。

Code

代码

#include <stdio.h>
#include <stdlib.h>

void gotoxy(int x,int y)
{
    printf("%c[%d;%df",0x1B,y,x);
}

int main(void)
{
    gotoxy(10,10);
    printf("hello world");
    return 0;
}