个性化阅读
专注于IT技术分析

c strcmp()函数

点击下载

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

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

#include<stdio.h>
#include <string.h>  
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
赞(0)
未经允许不得转载:srcmini » c strcmp()函数

评论 抢沙发

评论前必须登录!