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. memcached整理の内存管理及删除机制

    内存的碎片化 如果用C语言直接malloc,free来向操作系统申请和释放内存时,在不断申请和释放的过程中,形成了一些很小的内存片段,无法再利用.这种空闲但无法利用内存的现象称为内存的碎片化. sla ...

  2. .Net程序随系统开机启动(仿Foxmail托盘效果控制)

    对于使.NET程序随系统开机启动,最常用的可能就是向在注册表中注册开机启动项,或是建立Windows服务,使程序随系统启动而启动.这里以WinForm程序为例,测试Demo分享,同时附上对于程序托盘的 ...

  3. Replication--数据库镜像阻塞复制日志读取器的解决的办法

    问题描述:在同一数据库上使用镜像和复制,为保证镜像切换后,复制还能继续,因此当镜像断开或暂停时,复制日志读取器会被阻塞直到日志被同步到镜像从服务器端(无论异步还是同步).日志状态显示:复制的事务正等待 ...

  4. 基于GOJS绘制流程图

    基于GOJS封装的流程图设计(展示)工具类,主要分为两个工具类: 工具库依赖于go.js.jquery以及layer.js http://gojs.net/ http://jquery.com/ ht ...

  5. 201621123012 《Java程序设计》第9周学习总结

    1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结集合与泛型相关内容. 1.2 选做:收集你认为有用的代码片段 2. 书面作业 本次作业题集集合 1. List中指定元素的删除(题集 ...

  6. Python 的web自动化测试

    安装selenium 上面python已安装完毕,接下来安装selenium. 安装selenium之前需安装些必要工具 1. 安装setuptools 下载地址:https://pypi.pytho ...

  7. Servlet实现禁用cookie重写URL获取session

    前言 一个女人让他的程序员丈夫去商店买东西:你去附近的商店买些鸡蛋,如果有香蕉的话,买8个回来,这个丈夫买了8个鸡蛋回来,他的妻子大吃一惊:你为什么买了8个鸡蛋?! 程序员丈夫回答:因为他们有香蕉. ...

  8. 洛谷P4705 玩游戏(生成函数+多项式运算)

    题面 传送门 题解 妈呀这辣鸡题目调了我整整三天--最后发现竟然是因为分治\(NTT\)之后的多项式长度不是\(2\)的幂导致把多项式的值存下来的时候发生了一些玄学错误--玄学到了我\(WA\)的点全 ...

  9. 在iOS7中修改键盘Return键的类型

    今天将之前运行在iOS7之前的一段代码拿出来,在iOS7的机器上运行,发现键盘上的ReturnKeyType不能被修改了. 经过几番查找资料,了解到iOS7中UISearchBar的结构发生了变化,将 ...

  10. PHP curl 上传文件版本兼容问题

    [摘要:做微疑开辟挪用微疑接心上传文件时,总是返回 {"errcode":41005,"errmsg":"media data missing hin ...