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. fiddler-实现https抓包

    1. fiddler设置-fiddler options-https项进行设置,如下:   2. ie代理设置:连接-局域网设置 3. 下载fiddler根证书,ie浏览器上打开地址:http://1 ...

  2. MyBatis 一级缓存避坑

    MyBatis 一级缓存(MyBaits 称其为 Local Cache)无法关闭,但是有两种级别可选: package org.apache.ibatis.session; /** * @autho ...

  3. Verilog MIPS32 CPU(三)-- ALU

    Verilog MIPS32 CPU(一)-- PC寄存器 Verilog MIPS32 CPU(二)-- Regfiles Verilog MIPS32 CPU(三)-- ALU Verilog M ...

  4. c# winform实现同时只允许账号在一台电脑登录的功能

    公司有个小需求,要求账号不能同时登录在多台电脑上,就像那个微信或QQ一样,如果一台电脑登录了,原来登录的就自动退出了(网上搜索点单点登录,发现有些出入,人家是实现一次登录在多个系统间认证的) 找了些资 ...

  5. javaScript prototype实例(正则) 自定义日期格式化方法

    一个JS自定义日期格式化方法,包括了不少知识点,以下方法来自jQuery DataTable中文的官方参考 //return (new Date(data)).Format("yyyy-MM ...

  6. mongodb 片键

    mongodb  片键 mongodb的片键是很难控制的,没有完美的片键,只能均衡即可: 片键的方案: 1.id的hashed: 作为第一个方案,你可以使用数据文档_id的哈希作为片键. 这个方案能够 ...

  7. DIOCP (一) DIOCP常见问题。

    1,IOCP是什么? 答:IOCP是windows下的服务器技术,并不是所有windows都能使用IOCP,只能在支持IOCP的windows操作系统上使用. 2,DIOCP是什么? 答:DIOCP是 ...

  8. Python3.6引入的f-string 与 Python 3的新的特性:类型注解;

    f-string 1.介绍 f-string(formatted string literals):格式化字符串常量,是Python3.6新引入的一种字符串格式化方法,使格式化字符串的操作更加简便. ...

  9. php数据库编程---mysqli扩展库

    1,mysqli扩展库允许我们访问MySQL数据库,并对MySql数据库进行curd操作.Mysqli扩展库比mysql扩展库加强了. 2,mysqli扩展库和mysql扩展库的比较 (1) mysq ...

  10. UIEvent笔记

    UIEvent是什么 代表iOS系统中的一个事件. UIEvent分为三类,touch events, motion events, and remote-control events touch e ...