#include <string.h>
size_t strlen(const char *s);

功能:计算指定指定字符串s的长度,不包含字符串结束符‘\0’

参数:

  • s:字符串首地址

返回值:字符串s的长度,size_t为unsigned int类型

案例

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

int main(void)
{
    // strlen()
    // 计算字符串有效个数
    char ch5[100] = "hello world";
    printf("数组大小:%d\n", sizeof(ch5));
    printf("字符串长度:%d\n",strlen(ch5));
    // 代码实现计算字符串有效个数
    int len = 0;
    while (ch5[len] != '\n')len++;
    printf("字符串长度:%d\n", len);

    return 0;
}
strlen 使用案例

相关文章:

  • 2021-12-18
  • 2021-07-26
  • 2021-11-05
  • 2021-12-03
  • 2021-11-30
  • 2021-12-21
  • 2021-10-12
猜你喜欢
  • 2021-07-17
  • 2021-07-11
  • 2021-11-23
  • 2022-03-11
  • 2021-12-28
  • 2021-09-11
  • 2021-07-23
相关资源
相似解决方案