mardi 22 juin 2021

What is the problem in this code when I run the code it does not give the desired output

#include<stdio.h>
#include<string.h>
#include<conio.h>
int main()
{
char pwd[5];
int i;
printf("Enter your password: ");
for(i=0;i<=3;i++)
{
pwd[i]=_getch();
printf("%c",pwd[i]);
 if(pwd[i]==8)
  {
    if(i>0)
    {
    printf(" \b");
    i--;
    continue;
    }
    else
        break;
  }
}
pwd[i]='\0';
if(strcmp(pwd,"abcd")==0)
{
printf("\nPassword is correct");
}
else
{
printf("\nPassword is not correct");
}
return 0;
}

I want output in such form that when the user press backspace the previous character should be deleted and the user should be allowed to re-enter the previous character but this code has some problems in it. It deletes the previous character but doesn't allow to re-enter previous corrected character instead it takes it as next character what is the problem with this code please explain?

Aucun commentaire:

Enregistrer un commentaire