I have a piece of code that checks the hash of the guessed password.

if (temp == val)
                printf("%s\n", paswrd);
                return 0;
            else {
                printf("Not same\n");
                eprintf("%s\n", val);
                eprintf("%s\n", temp);

Temp is the entered hash. Val is the hash crypt makes. I have an eprintf above this which outputs temp and val. They are the same. (The test password I made is A.) However, the if statement prints Not same. Then it eprintfs val and temp again, and they are the same, again. I also measured the strlen and they have the same length, so no extra spaces. Why is this happening?

1 Answer 1


From the context I suppose you want to compare two strings, this can not be done with the == operator (only compare two pointers, which in this case are not the same). You will need a function called strcmp () from the standard library string.h , its use is simple. The value returned by this function is zero if both strings are equal:

 #include <string.h>

 if (strcmp(temp,val) == 0)
     printf("Are the same!.\n");

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .