字符串比较函数strcmp

格式:  strcmp(字符数组名1,字符数组名2)
功能:按照ASCII码顺序比较两个数组中的字符串,并由函数返回值返回比较结果。
    字符串1=字符串2,返回值=0;
    字符串2〉字符串2,返回值〉0;
    字符串1〈字符串2,返回值〈0。

本函数也可用于比较两个字符串常量,或比较数组和字符串常量。

ANSI标准规定,返回值有正数,负数,0.而确切数值是依赖不同的C实现的。

Return Value

Returns an integral value indicating the relationship between the strings:
return value indicates
<0 the first character that does not match has a lower value in ptr1 than in ptr2
0 the contents of both strings are equal
>0 the first character that does not match has a greater value in ptr1 than in ptr2


1.一般来说,返回值会是:1 0 -1

关于字符串比较函数strcmp返回值的问题


2.有些会把两个字符的ASCII码之差作为比较结果由函数值返回。

关于字符串比较函数strcmp返回值的问题

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-09-25
  • 2022-12-23
  • 2021-06-18
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-02-07
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-21
  • 2021-10-01
  • 2022-12-23
相关资源
相似解决方案