Thread: Trying to compare to strings...

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Dec 2002
    Posts
    28

    Trying to compare to strings...

    No matter what the strings are this program always reads them as different strings...

    Code:
    #include <iostream>
    #include <stdlib.h>
    #include <string.h>
    
    
    int main(int argc, char *argv[])
    {
    
      char string1[20], string2[20];
      
      cout<<"Input 2 strings. This program will tell you if the 2\n strings are excactly the same  ";
      
      cin.getline(string1, 20);
      cout<<'\n';
      cin.getline(string2, 20);
      
      cout<<"The 2 strings you entered were "<<string1<<" and "<<string2<<'\n';
     
     strcmp(string1, string2);
      
      
          if(string1 == string2)
           {
             cout<<"The two strings you entered are the same";
           }
      
          if(string1 != string2)
           {
            cout<<"The two strings you entered are not the same";
           }
        
      system("PAUSE");	
      return 0;
    }
    Can someone explain why this isnt working and what i need to do to get it to work? Thankyou.
    Last edited by imortal; 05-16-2003 at 10:40 AM.
    ~matt~

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compare strings problem
    By chelito19 in forum C Programming
    Replies: 2
    Last Post: 04-16-2009, 08:01 PM
  2. how do i compare first letters in two strings?
    By MalickT in forum C Programming
    Replies: 8
    Last Post: 04-20-2008, 05:47 PM
  3. compare strings not working
    By gtriarhos in forum C Programming
    Replies: 7
    Last Post: 09-29-2005, 12:51 PM
  4. using Stacks & Queues to compare Strings
    By eskimo083 in forum C++ Programming
    Replies: 1
    Last Post: 03-09-2003, 05:03 PM
  5. how do i compare strings
    By bart in forum C++ Programming
    Replies: 17
    Last Post: 08-30-2001, 09:17 PM