0
I need to register N people in my program with only two information: name and password. Then the user enters a name, if this name is not registered the program displays a message of no registration and closes, but if Tver registered it asks the password, if the password is correct the program only shows a message if access allowed, if the password is wrong the user has 3 chances to hit, if in the 3 chances he misses the program closes. The problem is that my program is taking the password of person 1 and adding the name of person 2 and I am not able to identify the error, since the password has only 6 memory fields.
#define N 5
struct pessoa
{
    char nome[30];
    char senha[6];
};
int main()
{
    struct pessoa cadastro[N];
    int i,j;
    char nome[30],senha[6];
    for(i=0;i<N;i++)
    {
        puts("\nDigite o nome:\n");
        fflush(stdin);
        gets(cadastro[i].nome);
        puts("\nInsira uma senha de ate 6 digitos:\n");
        fflush(stdin);
        gets(cadastro[i].senha);
    }
    system("cls");
    puts("\nInsira um nome:");//nome de busca
    fflush(stdin);
    gets(nome);
    for(i=0;i<N;i++)
    {
        printf("%s",cadastro[i].senha);// este printf só coloquei pra ver o que estava sendo armazenado em cadast[i].senha
        if(strcmp(cadastro[i].nome,nome)==0)
        {
            do
            {
                puts("\nInforme sua senha:");
                fflush(stdin);
                gets(senha);
                if(strcmp(cadastro[i].senha,senha)==0)
                {
                    j=0;
                    puts("\nAcesso permitido.");
                    break;
                }
                else
                {
                    j=j+1;
                    puts("\nSenha incorreta.");
                    if(j==3)
                    {
                        break;
                        return 0;
                    }
                }
            }while (j!=0);
        }
        else
        {puts("\nNome nao cadastrado.\n");}break;
    }
return 0;
}