#include <string.h>
int strncmp(const char *s1, const char *s2, size_t n);

功能:比较 s1 和 s2 前n个字符的大小,比较的是字符ASCII码大小。

参数:

  •        s1:字符串1首地址
  •        s2:字符串2首地址
  •        n:指定比较字符串的数量

返回值:

  •        相等:0
  •        大于: > 0
  •        小于: < 0

案例

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>

int main(void)
{
    char ch1[] = "hello world";
    char ch2[] = "hallo world";

    // 两个有限字符串比较
    int    value = strncmp(ch1, ch2);

    // 返回为1不相等
    printf("%d\n", value);

    return 0;
}
strncmp 使用案例:使用函数

相关文章:

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