1

While coding in C and printing output to the screen, can we print to a different position on the screen without using \t\t\t? The location should be specified by coordinates of some kind.

E.g. printf("hallo hai")

The above print message would appear where we desire. It should not use \t\t\t but instead be placed at a numerically expressed position.

Don Cruickshank
  • 5,641
  • 6
  • 48
  • 48
Saifuddeen
  • 11
  • 3

1 Answers1

0

I would suggest you to go with curses or its updates ncurses.

The following code prints hello world using ncurses :

/*
  "Hello, world!", ncurses style.
*/


#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>                  /*  for sleep()  */
#include <curses.h>


int main(void) {

    WINDOW * mainwin;


    /*  Initialize ncurses  */

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


    /*  Display "Hello, world!" in the centre of the
    screen, call refresh() to show our changes, and
    sleep() for a few seconds to get the full screen effect  */

    mvaddstr(13, 33, "Hello, world!");
    refresh();
    sleep(3);


    /*  Clean up after ourselves  */

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

    return EXIT_SUCCESS;
}
Mathews Sunny
  • 1,796
  • 7
  • 21
  • 31