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

【c strcmp()函数】输出:
Enter 1st string: hello Enter 2nd string: hello Strings are equal

    推荐阅读