c - Strcmp does not do the comparing -
why isn't comparing between strings work? know user
strings not have endlines @ end of them, still username not accepted.
char user[24]; int userlog = -1; file *usernames; usernames = fopen("usernames.cfg", "r"); if (usernames == null){ perror("usernames - err"); return(-1); } while(fgets(user, sizeof(user), usernames) !=null){ strtok(user, "\n"); printf("%s -- %s\n", user, possibleusername); // first edition of question contained: // if((possibleusername, user) == 0) // still having problems version: if(strcmp(possibleusername, user) == 0) userlog = 1; else userlog = 0; } if(userlog == 1) printf("username accepted: %s\n", possibleusername); else if(userlog == 0) printf("username doesn't exist in database.\n"); fclose(usernames);
usernames.cfg:
user justplayit etc
i suppose should be
if(strcmp(possibleusername, user) == 0)
because expression
(possibleusername, user) == 0
is equal to
user == null
edit
change
int userlog = -1;
to
int userlog = 0;
and delete
else userlog = 0;
Comments
Post a Comment