Home >>C String functions >C strcmp() function

C strcmp() function

C strcmp() function

C Strcmp() function compares two string and return 0 if both strings are equal.

Syntax:
Strcmp(str1,str2)

Note:- Here str is given string.

Parameters:-

It takes strings as parameter.

Return type:-

It returns 0 or 1.

Example-1

#include <stdio.h>
#include <string.h>
int main(){    
  char str1[20],str2[20];    
  printf("Enter 1st string: ");    
  gets(str1);   
  printf("Enter 2nd string: ");    
  gets(str2);    
  if(strcmp(str1,str2)==0)    
      printf("Strings are equal");    
  else    
      printf("Strings are not equal");    
 return 0;    
}    

Output:
Enter 1st string: phptpoint
Enter 2nd string: phptpoint
Strings are equal

No Sidebar ads