Jyothis V James
Jyothis V James

Reputation: 1

How can I erase the current line printed on console in C from the end?

I need to erase a printed character in a new line from the end. That is if the statement is printf("C++") I need to erase those 2 "++" printed and get the output "C".

    printf("hello");   printf("\rbye");

Using the above escape sequence '\r', replaces it only from the printed line beginning to get the output 'byelo', how to do it from the end to get 'hebye'?

Upvotes: 0

Views: 294

Answers (1)

Alexander Udalov
Alexander Udalov

Reputation: 32826

You can use the backspace ASCII character:

printf("hello");
printf("\b");

Result:

hell

UPD: see also this answer

Upvotes: 1

Related Questions