cubuntugccconio

How could I achieve gotoxy() in 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.

required output

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?


Solution

  • Use the ncurses library.

    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.\n");
            exit(EXIT_FAILURE);
        }
    
        move(10, 15);
        addch('X');
        refresh();
    
        getch();
    
        delwin(mainwin);
        endwin();
        refresh();
    
        return EXIT_SUCCESS;
    }
    

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