我如何在 gcc 中实现 gotoxy() [英] How could I achieve gotoxy() in gcc

查看:16
本文介绍了我如何在 gcc 中实现 gotoxy()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在ubuntu中使用gcc.所以,我在终端中编译和执行.但是在在线编程比赛中,他们需要如图所示的输出.

I am using gcc in ubuntu.so, I compile and execute in terminal. But In a online programming contest, they require the output as shown in diagram.

为此,如果我使用 TURBOC 我可以使用 conio.h 使用 gotoxy() 来获得 螺旋格式 的输出.但是在 Ubuntu 中,我该如何实现呢?

For that, if I use TURBOC I can get it using conio.h using gotoxy() to get spiral format of output. But in Ubuntu , How could I achieve this?

推荐答案

使用 ncurses 库.

Use the ncurses library.

这是一个例子,改编自 http://www.paulgriffiths.net/程序/c/srcs/curhellosrc.html

Here's an example, adapted from http://www.paulgriffiths.net/program/c/srcs/curhellosrc.html

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

int main(void) {
    WINDOW * mainwin;

    /*  Initialize ncurses  */

    if ( (mainwin = initscr()) == NULL ) {
        fprintf(stderr, "Error initialising ncurses.
");
        exit(EXIT_FAILURE);
    }

    move(10, 15);
    addch('X');
    refresh();

    getch();

    delwin(mainwin);
    endwin();
    refresh();

    return EXIT_SUCCESS;
}

更多信息可在此处获得:http://invisible-island.net/ncurses/ncurses-intro.html#stdscr

Further information is available here: http://invisible-island.net/ncurses/ncurses-intro.html#stdscr

这篇关于我如何在 gcc 中实现 gotoxy()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆