The console freezes at the keyboard input using getch ()

0

Why does not this code work for me? I do not see where the fault may be, I know that the conio library is not standard, but anyway it should work ...

#include <stdlib.h> 
#include <conio.h>   
int main()
{   
    char password[10];
    char c;
    int i=0;
    c=getch();
    while( (c=getch()) != '\n')
    {
        password[i] = c;
        printf("*");
        i++;
    }
    password[i] = c;

    return 0;
}

The error is that after entering the enter it keeps asking for characters and then it hangs up ...

    
asked by EmiliOrtega 17.02.2017 в 18:14
source

1 answer

-1

I assume you want to make a password algorithm

#include <stdlib.h>
#include <conio.h>
#include <stdio.h>

int main()
{
    char password[10];
    for(int i=0; i<10; i++)
    {
        password[i]=getch();
        if (password[i]== char(13))
        {
            password[i]='
#include <stdlib.h>
#include <conio.h>
#include <stdio.h>

int main()
{
    char password[10];
    for(int i=0; i<10; i++)
    {
        password[i]=getch();
        if (password[i]== char(13))
        {
            password[i]='%pre%';
            break;
        }
        printf("*");
    }
    return 0;
}
'; break; } printf("*"); } return 0; }

That's how Emily should work

    
answered by 17.02.2017 в 20:08