adsense

Hii, welcome to my site. My name is Om prakash kartik. This blog helps you to learn programming languages concepts.

Program in C++ to compare two string

Program in C++ to compare two string 



 #include<iostream>
 #include<conio.h>
 #include<string.h>
  using namespace std;
  int StrCmp(char *str1,char *str2)
    {
      int i,l1,l2,c=0;
      l1=strlen(str1);
    l2=strlen(str2);
      if(l1==l2)
         {
          for(i=0;i<l1;i++)
           {
     if(str1[i]==str2[i])
               {
                  c++;
       } 
     }
    if(c==l1)
        return 0;
    else
       return 1;
   }
  else
     return 1;
  }

  int main()
    {
        char str[100],str1[100];
        cout<<" Enter first words:-";
        cin.getline(str,99);
        cout<<" Enter second words:-";
        cin.getline(str1,99);
        if(StrCmp(str,str1)==0)
          cout<<"Equals.";
        else 
          cout<<"Not equals.";
        getch();
    }
Output:-













Related Programs -


  1. Program in C++ to copy one word into another word
  2. Program in C++ to add two string
  3. Program in C++ to convert string Uppercase to Lowercase
  4. Program in C++ to convert string  Lowercase to Uppercase 
  5. Program in C++ to count words in given sentence


Post a Comment

0 Comments