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 ...
随机推荐
- redis整理の走进redis世界
声明:原文摘自http://weibo.com/u/2446082491,谢谢他的分享! 在当前大型互联网应用以及提供云计算服务的时候,怎样保证系统在海量数据环境下的高性 能.高可靠性.高扩展性.高可 ...
- 13 Amazing Component Sets Driving Success In Delphi Berlin On Android And IOS
There are quite a few Firemonkey component sets available for Delphi Berlin which can get you ahead ...
- 实体bean里面不要轻易加transient,反序列回来之后会变成null
实体bean里面不要轻易加transient,反序列回来之后会变成null
- Kid的某些跳刺套路
需要按二段方向键的跳跃: 中途松开方向键的跳跃: 中途按下方向键的跳跃: 意想不到的小跳(如果上方有墙,小跳比大跳磕头跳的更远)(kid站的是最后的位置): 意想不到的小跳*2: 意想不到的小跳*3( ...
- String 源码浅析(一)
前言 相信作为 JAVAER,平时编码时使用最多的必然是 String 字符串,而相信应该存在不少人对于 String 的 api 很熟悉了,但没有看过其源码实现,其实我个人觉得对于 api 的使用, ...
- orange
选型:使用orange系统 orange与kong的比较1.kong整体代码上较凌乱, orange相对较有条理2.kong本身不支持后台管理页面,只能通过api方式增,删,改plugin, oran ...
- 如何在NSDocumentDirectory内新建一个文件夹
iOS下载文件一般保存到NSDocumentDirectory内,但是为了更好整理文件内容,那就要自定义的生成一些文件夹,和做一些删除文件夹的操作. - (NSString *)pathToPatie ...
- sql 列集合
STUFF((SELECT ','+CAST( TYZ_Bh as varchar(10)) FROM #1 where 片区划分='江东' for xml path('')),1,1,'')
- jenkins 判断是手动触发还是定时器触发
根据变量BUILD_CAUSE的值可以判断本次触发是手动触发还是定时器触发 手动触发:MANUALTRIGGER 定时器触发:TIMERTRIGGER
- python高级(二)—— python内置序列类型
本文主要内容 序列类型分类: (1)容器序列.扁平序列 (2)可变序列.不可变序列 列表推导式 生成器表达式 元组拆包 切片 排序(list.sort方法和sorted函数) bisect pytho ...