📜  C strcmp()函数

📅  最后修改于: 2020-10-22 05:32:52             🧑  作者: Mango

C比较字符串:strcmp()

strcmp(first_string,second_string)函数比较两个字符串,如果两个字符串相等,则返回0。

在这里,我们使用gets()函数从控制台读取字符串。

#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;  
}  

输出:

Enter 1st string: hello
Enter 2nd string: hello
Strings are equal