Compare two simple strings in C, input with scanf (); [duplicate]

0

What I want to do is very simple. I make the program ask for a password, the program compares, and if the password is valid, the program proceeds.

An example:

char pass[5];

printf("insira a senha: ");

while(pass!="asdfg") { //enquanto a senha for diferente/inválida
    scanf("%s",&pass); //entrada da senha
};

When I try to run this code, the program simply does not accept the asdfg password and still asks for the password.

    
asked by anonymous 20.09.2017 / 20:55

1 answer

0

When you get a string you do not need to use & , J string name is already a memory address.

char pass[5];

printf("insira a senha: ");

while(!strcmp(pass,"asdfg")) { //enquanto a senha for diferente/inválida
    scanf("%s", pass); //entrada da senha
};
    
20.09.2017 / 21:05