strlen

  • Returns the length of the C string str.
  • The length of a C string is determined by the terminating null-character: A C string is as long as the number of characters between the beginning of the string and the terminating null character (without including the terminating null character itself).
  • 返回给定空终止字符串的长度,即首元素为 str 所指,且不包含首个空字符的字符数组中的字符数。
  • 计算字符串 str 的长度,直到空结束字符,但不包括空结束字符。
  • 若 str 不是指向空终止字节字符串的指针则行为未定义。
size_t strlen( const char *str );

Parameters

str

  • C string.
  • 要计算长度的字符串。

Return Value

  • The length of string.
  • 该函数返回字符串的长度。

Example

//
// Created by zhangrongxiang on 2018/2/7 10:41
// File strlen
// #include <stdio.h>
#include <string.h> //Software is like sex: it"s better when it"s free.
//My name is Linus, and I am your God
//Linux is obsolete.
//Linux is not Unix int main() {
char *str = "My name is Linus, and I am your God";
size_t length = strlen(str);
printf("%s --> length is %d\n", str, (int) length); char *str2 = "一切皆文件";
length = strlen(str2);
printf("%s -- length --> %d\n", str2, (int) length); //15 = 3 * 15
printf("%s -- sizeof --> %d\n", str2, (int) sizeof("一切皆文件")); //16 = 3 * 5 + 1 char str3[] = "万物皆对象";
printf("%s -- sizeof --> %d\n", str3, (int) sizeof(str3)); //16 = 3 * 5 + 1 return 0;
}

文章参考

转载注明出处

C 标准库 - string.h之strlen使用的更多相关文章

  1. C 标准库 - string.h

    C 标准库 - string.h This header file defines several functions to manipulate C strings and arrays. stri ...

  2. C标准库<string.h>实现

    本文地址:http://www.cnblogs.com/archimedes/p/c-library-string.html,转载请注明源地址. 1.背景知识 <string.h>中声明的 ...

  3. C标准库string.h中几个常用函数的使用详解

    strlen 计算字符串长度 size_t strlen(const char *str) 计算字符串 str 的长度,直到空结束字符,但不包括空结束字符. 函数实现: int Strlen(cons ...

  4. C 标准库 - string.h之memmove使用

    memmove Move block of memory Copies the values of num bytes from the location pointed by source to t ...

  5. C 标准库 - string.h之memcpy使用

    memcpy Copy block of memory Copies the values of num bytes from the location pointed to by source di ...

  6. C 标准库 - string.h之memcmp使用

    memcmp Compare two blocks of memory. Compares the first num bytes of the block of memory pointed by ...

  7. C 标准库 - string.h之memchr使用

    memchr Locate character in block of memory,Searches within the first num bytes of the block of memor ...

  8. C 标准库 - string.h之strpbrk使用

    strpbrk Locate characters in string,Returns a pointer to the first occurrence in str1 of any of the ...

  9. C 标准库 - string.h之strrchr使用

    strrchr Locate last occurrence of character in string, Returns a pointer to the last occurrence of c ...

随机推荐

  1. MongoDb安全配置:简单的身份认证

    mongod默认启动不加任何参数时,是没有身份认证的,任何人都可以登录上进行任何操作 启动时添加--auth可以使用身份验证模式 使用mongod -f mongod.conf配置文件启动时,配置文件 ...

  2. git command cheat sheet

    clone:克隆 --non-bare:(默认值)一般的克隆方式 --bare:只克隆.git目录 --mirror:只克隆.git目录,并且还保持与origin的关联,可以fetch commit: ...

  3. 数据库_mysql多表操作

    多表操作        实际开发中,一个项目通常需要很多张表才能完成.例如:一个商城项目就需要分类表(category).商品表(products).订单表(orders)等多张表.且这些表的数据之间 ...

  4. javascript 获取iframe里页面中元素值的方法 关于contentWindow和contentDocumen

    javascript 获取iframe里页面中元素值的方法 IE方法:document.frames['myFrame'].document.getElementById('test').value; ...

  5. LightOJ 1234 Harmonic Number(打表 + 技巧)

    http://lightoj.com/volume_showproblem.php?problem=1234 Harmonic Number Time Limit:3000MS     Memory ...

  6. Jenkins安装笔记

    自动化架构搭建过程中为实现当开发源码更新时自动化脚本同步触发自动执行,使用到持续集成工具Jenikins. Jenikins官网资料: 官方网站:http://jenkins-ci.org/ 插件下载 ...

  7. coffee主题美化内容概要

    1.具备自动生浮动标题目录(可隐藏) 2.页首目录概要 3.主标题有明显的标志背景颜色,二级标题缩进合适 4.一级.二级标题下图片缩进合适 5.博客签名 6.背景音乐列表 7.打赏 8.联系方式(QQ ...

  8. WinForm Column cannot be added because its CellType property is null.

    在Winform  DatatGridView 控件中绑定了一个模型的属性,结果在生成窗口时,发生错误,异常信息如下 : Column cannot be added because its Cell ...

  9. js项目

    https://bbs.csdn.net/topics/320029234 文本实现悬挂缩进 牛逼牛逼 这是真的牛逼 p:first-letter {         margin-left: -2e ...

  10. linux命令提示符[root@localhost ~]#详解

    [root@localhost ~]#   1. @之前代表当前登录用户 在Linux中管理员用户是root,还有一些普通用户: 在此例中,root代表当前登录用户   2. @之后代表当前计算机主机 ...