so while writing code reason when comparing char in struct user input doesn't pass true when should be. unless user input somehow not same.
struct user { char login[11]; }; int main() { char input_login[11]; struct user goku; strcpy(goku.login,"goku"); printf("please enter login:"); fgets(input_login,11,stdin); printf("please enter password:"); fgets(input_password,11,stdin); if (strcmp(goku.login, input_login) == 0) // not working { printf("correct"); } else { printf("%s",goku.login); } return 0; }
function fgets
places in character array new line character corresponds pressed enter key if there enough space in string.
you should remove character.
for example
fgets(input_login,11,stdin); input_login[strcspn( input_login, "\n" )] = '\0';
Comments
Post a Comment