If(char != char) is not working... help?

This is a discussion on If(char != char) is not working... help? within the Game Programming forums, part of the General Programming Boards category; I am am having some problembs with a curent if function and i am wonder what i did wrong/what i ...

  1. #1
    Unregistered
    Guest

    If(char != char) is not working... help?

    I am am having some problembs with a curent if function and i am wonder what i did wrong/what i can do to fix it:
    here is the relavent info:

    char pword[20] = " ", pword2[20];

    if(pword != pword2)
    {
    cout << "incorrect password, please try again:" << endl;
    goto password2;
    }

    This statemt is always false... What did i do wrong?

  2. #2
    Registered User sean345's Avatar
    Join Date
    Mar 2002
    Posts
    346
    In order to compare two strings you need to use strcmp.
    Code:
    if(strcmp(pword,pword2)==0){
    //They are the same
    }
    else{
    //They are different
    }
    - Sean

  3. #3
    Unregistered
    Guest
    it seems like it is working, but the compiler doesnt recognize it... Is there a header file to go with this?

  4. #4
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,386
    You should include string.h.

  5. #5
    Unregistered
    Guest
    Thanx! Now it works!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 8
    Last Post: 12-21-2008, 08:42 PM
  2. Replies: 7
    Last Post: 06-16-2006, 09:23 PM
  3. code condensing
    By bcianfrocca in forum C++ Programming
    Replies: 4
    Last Post: 09-07-2005, 09:22 AM
  4. comparing fields in a text file
    By darfader in forum C Programming
    Replies: 9
    Last Post: 08-22-2003, 08:21 AM
  5. errors in class(urgent )
    By ayesha in forum C++ Programming
    Replies: 1
    Last Post: 11-10-2001, 09:14 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21