Ido Nir
Ido Nir

Reputation: 33

Delete User Input from the Terminal in C

I'm working on a program for Windows and Linux, coding it in C, and I want the program to get input from a user, show it until it finished (i.e. pressed 'enter'), then un-display what the user entered, finally re-displaying it with a time stamp.

It should look like this:

(Before user hits enter)

Enter a string: abcde

(Then after inputting the string "abcde")

|19:53| User: abcde

Currently what the program does is:

Enter a string: abcde

|19:53| User: abcde

Without the row of the input dissappearing.

Upvotes: 3

Views: 1065

Answers (1)

user13387119
user13387119

Reputation:

Well, it's hard. You have to go up one line to clear it. On Linux, you can use ANSI escape codes like "\033[A" to go up one line. There is no C standard way to do it.

If you print something and you are on the same line, use "\b" to backspace one character. From then, you can use white space to clear the inputs.

Upvotes: 3

Related Questions