Hi,
I am required to write a program in which a user will enter a password, and this password will be reversed and compared with the reverse of the actual password. In this case, the correct password is 'fred', but the program will compare 'derf' with 'derf', and the tell the user the password is correct.
Here is my current code:
At the moment, the program will reverse the word, but does not successfully carry out the 'if' condition execution.Code:/* Password Program */ /* By Luke Sowersby */ #include <stdio.h> #include <conio.h> #include <string.h> #define pass1 "derf" #define string_size 25 #define string_end (string_size-1) void string_swap(char[],char[]); void main(void) { char pass2[string_size], backwards[string_size]; printf("Please enter password:\n"); gets(pass2); string_swap(pass2, backwards); printf("Backwards: %s",backwards); if (backwards=="derf") printf("\nPass is correct"); else printf("\nPass is incorrect"); } void string_swap(char string[], char swap[]) { int i; for(i=0;i<(strlen(string));i++) { swap[(strlen(string)-1)-i]=string[i]; } swap[strlen(string)]=string[strlen(string)]; }
Can anyone help me please?
Thanks.



LinkBack URL
About LinkBacks


