string - strlen源码
2015-07-28 23:36
363 查看
[code]// // main.cpp // AUTO_PRO // // Created by yanzhengqing on 12-12-11. // Copyright (c) 2012年 yanzhengqing. All rights reserved. // #include using namespace std; /*** *strlen - return the length of a null-terminated string * *Purpose: * Finds the length in bytes of the given string, not including * the final null character. * *Entry: * const char * str - string whose length is to be computed * *Exit: * length of the string "str", exclusive of the final null byte * *Exceptions: * *******************************************************************************/ ///////////////////////////////////////////////////////////////////////////////// /*说明: 1. __cdecl 是C Declaration的缩写(declaration,声明),表示C语言默认的函数调用方法:所有参数从右到左依次入栈,这些参数由调用者清除,称为手动清栈。被调用函数不会要求调用者传递多少参数,调用者传递过多或者过少的参数,甚至完全不同的参数都不会产生编译阶段的错误。 2. 返回一个字符串的长度 3. 按照ANSI(American National Standards Institute)标准,不能对void指针进行算法操作,即不能对void指针进行如p++的操作,所以需要转换为具体的类型指针来操作,例如char *。(引用网友的结论) 4. size_t 类型定义在cstddef头文件中,该文件是C标准库的头文件stddef.h的C++版。它是一个与机器相关的unsigned类型,其大小足以保证存储内存中对象的大小。 */ size_t __cdecl strlen ( const char * str ) { const char *eos = str; while( *eos++ ); return( (int)(eos - str -1) ); } int main() { size_t k = 0; constchar brc[50] ="blog.csdn.net/barry_yan"; k =strlen(brc); cout<endl; return 0; }
相关文章推荐
- Data-Mining试题
- QQ空间蜘蛛爬虫数据报告
- 解决Eclipse中文乱码
- 把握linux内核设计思想(三):下半部机制之软中断
- java前奏及基础语法
- 深入探讨:标签(Tag)的各种设计方案
- IBM展望5年内电子产物将存在人类5小认知效率
- JavaScript 性能分析新工具 OneProfile
- PM日记:小试1 中午时光
- HDU 1950-最长上升子序的nlogn算法
- C标签定义变量,做加减乘除操作
- 内存空间的一般性区域分布图
- 百度竞价账户28原则操作实战篇
- 百度竞价账户28原则操作实战篇
- 欢迎使用CSDN-markdown编辑器
- 如何判断int类型大小及sizeof的用法
- 1、直接插入排序(InsertionSort)-C#实现
- JavaScript 性能分析新工具 OneProfile
- PHP一些优先级的问题
- Java--break continue