If your terminal supports ANSI Escape Codes, this will move the cursor up one line and then to column 10 and resume printing on the same line as the input for ui
.
#include <stdio.h>
int main()
{
int ui;
char up_from_down=179;
printf("%c",up_from_down);
scanf("%d",&ui);
printf ( "\033[1A");//move cursor up one line
printf ( "\033[10C");//move cursor 10 places
printf("1 %c\n",up_from_down);
return 0;
}
If you want the printing to more closely follow the input, use %n
to capture the number of characters processed by scanf
and use that value in the ANSI Escape Code.
#include <stdio.h>
int main()
{
int ui = 0;
int col = 0;
char up_from_down=179;
printf ( "%c", up_from_down);
fflush ( stdout);//no newline in printf so force printing
if ( 1 == scanf ( "%d%n", &ui, &col)) {
col += 2;
printf ( "\033[1A");//move cursor up one line
printf ( "\033[%dC", col);//move cursor to col
printf("1 %c\n",up_from_down);
}
return 0;
}