c - Acquire string from user and then delete it from screen -


this simple program acquires characters users (till newline character) , prints them:

#include <stdio.h>  int main() {     char local_message[200];     scanf("%[^\n]%*c", local_message);     printf("your message %s\n", local_message);      return 0; } 

but when run it, characters typed stay printed screen:

hello world! message hello world! 

the characters typed "hello world!\n". when press "enter" create newline \n character, message disappears screen (while being stored char array), can print (and format) following printf.

the os linux.

is possible? how?

you may able terminal escape codes.

#include <stdio.h>  int main ( ) {     char local_message[200];      scanf("%199[^\n]%*c", local_message);     printf ( "\033[0a");//move cursor 1 line     printf ( "\033[2k");//clear line     printf("\nyour message %s\n", local_message);      return 0; } 

edit:
give little more control , erase inputs more 1 line.

#include <stdio.h>  int main ( ) {     char local_message[200];      printf ( "\033[2j");//clear screen , move cursor upper left corner     printf ( "\033[8;h");//move cursor line 8     printf("enter message\n");     scanf("%199[^\n]%*c", local_message);     printf ( "\033[9;h");//move cursor line 9     printf ( "\033[j");//clear screen line end     printf ( "\033[12;h");//move cursor line 12     printf("\nyour message %s\n", local_message);      return 0; } 

Comments

Popular posts from this blog

php - Admin SDK -- get information about the group -

dns - How To Use Custom Nameserver On Free Cloudflare? -

Python Error - TypeError: input expected at most 1 arguments, got 3 -