C 标准库 - string.h之strlen使用
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;
}
文章参考
- http://zh.cppreference.com/w/c/string/byte/strlen
- http://www.cplusplus.com/reference/cstring/strlen/
- http://www.runoob.com/cprogramming/c-function-strlen.html
转载注明出处
C 标准库 - string.h之strlen使用的更多相关文章
- C 标准库 - string.h
C 标准库 - string.h This header file defines several functions to manipulate C strings and arrays. stri ...
- C标准库<string.h>实现
本文地址:http://www.cnblogs.com/archimedes/p/c-library-string.html,转载请注明源地址. 1.背景知识 <string.h>中声明的 ...
- C标准库string.h中几个常用函数的使用详解
strlen 计算字符串长度 size_t strlen(const char *str) 计算字符串 str 的长度,直到空结束字符,但不包括空结束字符. 函数实现: int Strlen(cons ...
- C 标准库 - string.h之memmove使用
memmove Move block of memory Copies the values of num bytes from the location pointed by source to t ...
- C 标准库 - string.h之memcpy使用
memcpy Copy block of memory Copies the values of num bytes from the location pointed to by source di ...
- C 标准库 - string.h之memcmp使用
memcmp Compare two blocks of memory. Compares the first num bytes of the block of memory pointed by ...
- C 标准库 - string.h之memchr使用
memchr Locate character in block of memory,Searches within the first num bytes of the block of memor ...
- C 标准库 - string.h之strpbrk使用
strpbrk Locate characters in string,Returns a pointer to the first occurrence in str1 of any of the ...
- C 标准库 - string.h之strrchr使用
strrchr Locate last occurrence of character in string, Returns a pointer to the last occurrence of c ...
随机推荐
- python3操作Excel openpyxl模块的使用
python 与excel 安装模块 本例子中使用的模块为: openpyxl 版本为2.4.8 安装方法请参看以前发表的文章(Python 的pip模块安装方法) Python处理Excel表格 使 ...
- java学习(一)数据类型
一.java的安装及环境变量的配置 http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.htm ...
- [LeetCode 题解]: Search a 2D Matrix
Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the follo ...
- INDEX--索引相关信息查看
--============================================== --查看可能缺失的索引 SELECT mig.* ,migs.* ,mid.* FROM sys.dm ...
- 一步一步教你如何制件 ZKEACMS 的扩展组件/插件
前言 如果你还不知道ZKEACMS,不妨先了解一下. ASP.NET MVC 开源建站系统 ZKEACMS 推荐,从此网站“拼”起来 官方地址:http://www.zkea.net/zkeacms ...
- OLEDB方式操作oracle数据库
OLEDB方式操作oracle数据库 一.查询语句: using (OleDbConnection conn = new OleDbConnection(System.Configuration.Co ...
- mongodb driver2.5环境注意事项
mongodb driver2.5环境注意事项 一.问题: 如果使用vs2012开发就会报这个错误: 未能加载文件或程序集“System.Runtime.InteropServices.Runtime ...
- CF|codeforces 280C Game on Tree
题目链接:戳我 大概题意:给一棵树,然后每次可以删除一个子树,问你期望多少次能把整棵树都删完? 概率和期望是个神仙..我不会 对于这个题,我们要有一个前置知识--期望的线性性,就是说总期望的值等于各个 ...
- poj 3468 A Simple Problem with Integers 线段树区间加,区间查询和(模板)
A Simple Problem with Integers Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://poj.org/problem?i ...
- 十九、Node.js-非阻塞IO、异步以及 '事件驱动EventEmitter'解决异步
1.Nodejs 的单线程 非阻塞 I/O 事件驱动 在 Java.PHP 或者.net 等服务器端语言中,会为每一个客户端连接创建一个新的线程而每个线程需要耗费大约 2MB 内存.也就是说,理论上, ...