C strcmp()

The strcmp(first_string, second_string) function compares two string and returns 0 if both strings are equal.

Here, we are using gets() function which reads string from the console.

snippet
#include
#include   
int main(){  
  char str1[20],str2[20];  
  printf("Enter 1st string: ");  
  gets(str1);//reads string from console  
  printf("Enter 2nd string: ");  
  gets(str2);  
  if(strcmp(str1,str2)==0)  
      printf("Strings are equal");  
  else  
      printf("Strings are not equal");  
 return 0;  
}

Output:

Output
Enter 1st string: hello Enter 2nd string: hello Strings are equal
Related Tutorial
Follow Us
https://www.facebook.com/Rookie-Nerd-638990322793530 https://twitter.com/RookieNerdTutor https://plus.google.com/b/117136517396468545840 #
Contents