First check the length of two string. if length of the two string are equal then Travel the source strings, and compare the character one by one. If all characters are same then print both strings are identical. We can also use strcmp() or strcmpi() or stricmp() method to compare two string. for that, we must include string.h header file.
#include<string.h> //for the method strlen() int main() { char str1[30],str2[30],i,fl=1; printf("Enter A String: "); gets(str1); printf("Enter Another String: "); gets(str2); if(strlen(str1)==strlen(str2)) { for(i=0;str1[i]!='\0';i++) { if(str1[i]!=str2[i]) { printf("Strings are not equal"); fl=0; break; } } if(fl) { printf("Strings are equal"); } } else { printf("Strings are not equal"); } return 0; }
#include<string.h> //for the method strlen() and strcmp() int main() { char str1[30],str2[30],i,fl=1; printf("Enter A String: "); gets(str1); printf("Enter Another String: "); gets(str2); if(strcmp(str1,str2)==0) { printf("Strings are equal"); } else { printf("Strings are not equal"); } return 0; }