If your terminal supports VT100 escape sequences , you can use them to move the cursor:
printf("\x1b[%uD", n); printf("\x1b[%uC", n); printf("\x1b[K"); printf("\x1b[1K"); printf("\x1b[2K");
Quick example ( curtest.c ):
#include <stdio.h> int main(void) { printf("ZZZZZZZZZZ"); printf("\x1b[%dD", 10U); /* move cursor 10 steps to the left */ printf("YYYYYYYYY"); printf("\x1b[%dD", 9U); /* move cursor 9 steps to the left */ printf("XXXXXXXX"); printf("\x1b[%dD", 2U); /* move cursor 2 steps to the left */ printf("\x1b[1K"); /* clear line from cursor to the left */ printf("\r\n"); return 0; }
If your terminal supports these escape codes, it should print
mizo@host :~/test> gcc curtest.c mizo@host :~/test> ./a.out XYZ mizo@host :~/test>
Windows command line does not have VT100 built-in support.
source share