1
I’m developing a program that needs to read a variable in char
and compare the same with another char
. However, when performing the comparisons using the function strcmp(typed_pass, correct_pass)
, independent of the text obtained through typed_pass
, the result is valid, ie 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 have already tried to carry out this operation through if
and validations by matrix position using a for
, both unsuccessful (using the for
an error has been returned to me).
Is there another way to do it or am I just missing in the creation of variables?
It is correct to set the variable
typed_pass
size 0?– Woss
I figured by setting the size to 0, the character allocation space would become dynamic.
– user34594