How to remove vector character by pressing backspace on c

0

Good Night .... I am doing an automatic login system and validation worked agr. The only problem is that it does not delete the previous character if the user misses the letter, I would like to know how to get the event of the user press the backspace key to delete the wrong character obs - code below

   #include <stdlib.h>
   #include <stdio.h>
   #include <windows.h>
   #include <string.h>
   char vetor[50];
   char user[]= "usuario";
   char senha[]= "senha";
   int i = 0, c, t=0, j=0, cont=0;

   int main(){

       void Validacao(char vetor[50],int valida, char desejado[50]);
       void ValidacaoSenha(char vetor[50],int valida, char desejado[50]);

       //para entrada e reconhecimento da senha versão 1.0
       printf("\n\n\n\n\n\n\n\n\n\n\n\n\t\t\t\t\t\tLogin >> ");
       Validacao(vetor,strlen(user),user);
   }

   void Validacao(char vetor[50],int valida, char desejado[50]){

       int i = 0, c, t=0, j=0, cont=0;

       do{
           c=getch();
           fflush(stdin);
           vetor[i] = c;

           printf("%c", vetor[i]);
           i++;

               if(vetor[j] == desejado[j]){
                   cont++;
               }
               j++;

           if(cont==valida){
               t=1;
           }
       } while (t!=1);
   }
    
asked by anonymous 09.11.2016 / 01:23

1 answer

0

First of all, getch() and fflush(stdin) are two of the most nefarious things in C; the former is not part of the pattern and the latter generates indefinite behavior. If the intention is just to read a user string, and then compare it to another string, there is no need to make character, do everything with same strings:

do {
    scanf(" %s", vetor);
} while(strcmp(vetor, desejado) != 0);

Note that reading only happens after the user types Enter . This also means that you will not enter more than 50 characters at a time.

    
09.11.2016 / 01:49