函数strcmp()的功能是对两个字符串进行比较。当s数组中字符串和t数组中字符串相等时,返回值为0;当s数组中字符串大于t数组中字符串时,返回值大于0;当s数组中字符串小于t数组中字符串时,返回值小于0.
以下是使用c语言实现strcmp()函数的完整代码:
#include <stdio.h>
#include <string.h>
int main(void)
{
char s[] = "Hello";
char t[] = "World";
int result;
result = strcmp(s, t);
if (result == 0)
{
printf("The strings are equal.\n");
}
else if (result > 0)
{
printf("The string in s is greater than the string in t.\n");
}
else
{
printf("The string in s is less than the string in t.\n");
}
return 0;
}