I'm developing a program that needs to read a variable in char
and compare it with another char
. However, when performing comparisons using the strcmp(typed_pass, correct_pass)
function, regardless of the text obtained through typed_pass
, the result is valid, that is, return 0.
int main (int argc, char *argv[]) {
char correct_pass[] = "test";
char typed_pass[0];
do {
printf ("\nTo unlock your last tip, enter the correct password: ");
scanf ("%s", typed_pass);
} while (strcmp(typed_pass, correct_pass));
printf ("\nOK!");
return;
}
I've already tried to do this with if
and matrix position validations using a for
, both of which were unsuccessful (using for
me an error was returned).
Is there another way to do it or am I just wrong in creating the variables?