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 -
- Program in C++ to copy one word into another word
- Program in C++ to add two string
- Program in C++ to convert string Uppercase to Lowercase
- Program in C++ to convert string Lowercase to Uppercase
- Program in C++ to count words in given sentence
0 Comments