LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-21-2017, 04:05 AM   #1
dani2304
LQ Newbie
 
Registered: Jan 2017
Posts: 1

Rep: Reputation: Disabled
Overwriting Console Output


Hello,
I got a problem trying to programm under Linux. I was trying to implement a fuction that will overwrite an input sentence. The function shall overwrite the read letters by hitting the Enter Button.

Code:
int main(void) {
    char Password[10];
    int i=0,j;
    do{
        Password[i]=getche();
        if(Password[i]!=8) i++;        
        else{                       // special case: Backspace
            printf(" \b");          
            if(i>0) i--;
        }
    }while(Password[i-1]!=13);
    for(j=0;j<i-1;j++)printf("*"); // overwrite it with '*'
    printf("\n%s",Password);
}
It works fine under Windows but there is no getche() function under Linux.

Do you know another possibility?

With best regards
 
Old 01-21-2017, 07:58 AM   #2
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,863
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
Function getpass might be your friend
http://www.gnu.org/software/libc/man...e/getpass.html
 
Old 01-21-2017, 10:46 AM   #3
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192Reputation: 3192
I am curious if you actually did any searching at all prior to asking your question? A quick google of "getche alternative in linux" returned me 34K+ results ... none of those any good??
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Separate output to serial console and screen console systemlordanubis Linux - Server 1 11-21-2014 03:27 AM
Tape Backup - mt erase, dd, and tar overwriting produce input/output error sp00led Linux - Newbie 9 04-28-2014 03:03 AM
Try to disable console output, console=null doesn't work embLinux Linux - Kernel 5 03-04-2014 03:21 AM
[SOLVED] Truncating an output file and overwriting its previous content moraxu Linux - Newbie 1 03-15-2013 01:44 PM
[SOLVED] Overwriting free space or overwriting single files restored by photorec fcrok Linux - Security 22 09-15-2012 12:53 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:30 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration