Thread: Password Program

  1. #1
    Registered User
    Join Date
    Mar 2009
    Posts
    19

    Password Program

    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:

    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)];
    }
    At the moment, the program will reverse the word, but does not successfully carry out the 'if' condition execution.

    Can anyone help me please?

    Thanks.

  2. #2
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    to compare strings use strcmp (read function description to know what the return value means)
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  3. #3
    Registered User
    Join Date
    Mar 2009
    Posts
    19
    Thanks... I managed to get it working.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  2. insufficient memory for tsr
    By manmohan in forum C Programming
    Replies: 8
    Last Post: 01-02-2004, 09:48 AM
  3. Date program starts DOS's date
    By jrahhali in forum C++ Programming
    Replies: 1
    Last Post: 11-24-2003, 05:23 PM
  4. Beginner needs help with password program
    By dnottus in forum C++ Programming
    Replies: 6
    Last Post: 04-22-2002, 06:46 PM
  5. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM