strrchr源码
2012-12-30 21:35
393 查看
//
// main.cpp
// AUTO_PRO
//
// Created by yanzhengqing on 12-12-11.
// Copyright (c) 2012年 yanzhengqing. All rights reserved.
//
#include <iostream>
using namespace
std;
/***
*char *strrchr(string, ch) - find last occurrence of ch in string
*
*Purpose:
* Finds the last occurrence of ch in string. The terminating
* null character is used as part of the search.
*
*Entry:
* char *string - string to search in
* char ch - character to search for
*
*Exit:
* returns a pointer to the last occurrence of ch in the given
* string
* returns NULL if ch does not occurr in the string
*
*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类型,其大小足以保证存储内存中对象的大小。
*/
char * __cdecl strrchr (
const
char * string,
int ch
)
{
char *start = (char *)string;
while (*string++)
/* find end of string */
;
/* search towards front */
while (--string != start && *string != (char)ch)
;
if (*string == (char)ch) /* char found ? */
return( (char *)string );
return(NULL);
}
int main()
{
char *p =
NULL;
int j =
0;
constchar brc[50]
="blog.csdn.net/barry_yan";
p =strrchr(brc,(int)'\0');
j = (int)'\0';
cout<<j<<endl;
if(p)
{
cout<<*p<<endl;
}
else
{
cout<<"null"<<endl;
}
return
0;
}
// main.cpp
// AUTO_PRO
//
// Created by yanzhengqing on 12-12-11.
// Copyright (c) 2012年 yanzhengqing. All rights reserved.
//
#include <iostream>
using namespace
std;
/***
*char *strrchr(string, ch) - find last occurrence of ch in string
*
*Purpose:
* Finds the last occurrence of ch in string. The terminating
* null character is used as part of the search.
*
*Entry:
* char *string - string to search in
* char ch - character to search for
*
*Exit:
* returns a pointer to the last occurrence of ch in the given
* string
* returns NULL if ch does not occurr in the string
*
*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类型,其大小足以保证存储内存中对象的大小。
*/
char * __cdecl strrchr (
const
char * string,
int ch
)
{
char *start = (char *)string;
while (*string++)
/* find end of string */
;
/* search towards front */
while (--string != start && *string != (char)ch)
;
if (*string == (char)ch) /* char found ? */
return( (char *)string );
return(NULL);
}
int main()
{
char *p =
NULL;
int j =
0;
constchar brc[50]
="blog.csdn.net/barry_yan";
p =strrchr(brc,(int)'\0');
j = (int)'\0';
cout<<j<<endl;
if(p)
{
cout<<*p<<endl;
}
else
{
cout<<"null"<<endl;
}
return
0;
}
相关文章推荐
- 上周Asp.net源码更新(1.7-1.11)
- Linux netfilter源码分析(2)
- jQuery 源码分析笔记(2)
- android多媒体播放源码解析
- Symbian俄罗斯方块游戏源码
- pandaboard----android源码下载问题
- 源码同步常见问题及处理方法
- 程序员表白程序,开放源码,不断更新
- linux 命令行参数解析源码
- 用命令编译、运行java项目(多个源码包,依赖第三方jar包)
- sequioadb源码分析
- 自动下载源码_并编译_打包_部署_重启服务的Shell脚本
- Caffe源码中各种依赖库的作用及简单使用
- 百度脑图源码
- Mac 10.11 android6.0源码编译
- JDK源码分析之String篇
- 基于LNMP的Zabbbix之PHP源码安装
- Android7.0 Messaging源码分析(0) - 启动篇
- 悟空分词的搜索和排序源码分析之——搜索
- request_resource_conflict 源码分析