zoukankan      html  css  js  c++  java
  • C语言 strlen

    C语言 strlen

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

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

    参数:

    • 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
    ", sizeof(ch5));
        printf("字符串长度:%d
    ",strlen(ch5));
        // 代码实现计算字符串有效个数
        int len = 0;
        while (ch5[len] != '
    ')len++;
        printf("字符串长度:%d
    ", len);
    
        return 0;
    }
    strlen 使用案例
  • 相关阅读:
    html例题——简历
    求值
    c#语句实例(排大小)
    3.6语言基础笔记
    2016.3.5进制间的转换
    3.26-1
    3.23(网页)
    3.23
    3.22
    3.20
  • 原文地址:https://www.cnblogs.com/xiangsikai/p/12373714.html
Copyright © 2011-2022 走看看