-
Still, using strcmp() or strncmp() which are standard, would be better. But you've seemed to ignore what people have said about using gets()!
Use fgets(), no excuses. Your code doesn't work in other words, what's to say I enter a password longer than 20 characters? Oops.
-
Besides agreeing that you should use fgets() [like I said earlier], you don't need to compare EVER character if you find a "mismatch". Just set "q" to something non-zero and break the loop (using "break;" in the "not equal" part, or by adding "&& !q" to the for-loop condition). It probably doesn't make any difference here, but wriitng code that does more than it needs to is always bad practice.
Of course, strcmp() would also be a good suggestion, it compares two strings - there's no reason not to trust strcmp(). [1]
The third thing is of course that password checking should not be done by comparing with a clear-text string - it should be done by storing a hashed value of the password and comparing the hash of the entered password with the stored value. But that is a more advanced topic.
[1] strncmp is an alternative, however, since at least one of the strings are known length and known to be "wellformed", I don't really see the point of using strncmp in this case.
--
Mats