Home > Back-end >  how to set cursor to previous line in c
how to set cursor to previous line in c

Time:11-29

I have been dealing with a issue that I cant solve in specifically c language in output terminal I want my cursor in previous line for example

prints("hello\n");
prints("Hi");

If want to print hi in near horizontal to hello but not my removing \n or by re writing anything I just want that after \n cursor go to previous line and print hi can anyone help me please

prints("\n hi\r\b");
prints("hello");

I wanted it to be like hello hi

CodePudding user response:

In pure C you can only edit your current line:

\b = 1 character back
\r = Beginning of line

You can go to every position like that (Windows):

#include <windows.h>

void goto_xy(unsigned x, unsigned y)
{
    SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), (COORD){x, y});
}

CodePudding user response:

If you want output like this hello hi the you have to remove '\n' like this

printf("hell hi");

But in your question you mentioned that you want to print hi near horizontal to hello without removing '\n'. As per my understanding you have to remove '\n' after hello.

  • Related