strrchr

  • Locate last occurrence of character in string, Returns a pointer to the last occurrence of character in the C string str.
  • The terminating null-character is considered part of the C string. Therefore, it can also be located to retrieve a pointer to the end of a string.
  • 寻找 ch (如同用 (char)ch 转换到 char 后)在 str 所指向的空终止字节串中(将每个字符转译成 unsigned char )的最后出现。若搜索 '\0' ,则认为终止空字符为字符串的一部分,而且能找到。
  • C 库函数 char *strrchr(const char *str, int c) 在参数 str 所指向的字符串中搜索最后一次出现字符 c(一个无符号字符)的位置。
  • 若 str 不是指向空终止字节串的指针,则行为未定义。
char *strrchr( const char *str, int ch );

Parameters

str

  • C string.
  • 指向要分析的空终止字节字符串的指针

character

  • Character to be located. It is passed as its int promotion, but it is internally converted back to char.
  • 要搜索的字符
  • 要搜索的字符。以 int 形式传递,但是最终会转换回 char 形式。

Return Value

  • A pointer to the last occurrence of character in str.If the character is not found, the function returns a null pointer.
  • 指向 str 中找到的字符的指针,或若找不到这种字符则为空指针。
  • 该函数返回 str 中最后一次出现字符 c 的位置。如果未找到该值,则函数返回一个空指针。

Example

//
// Created by zhangrongxiang on 2018/2/6 9:12
// File strrchr
// #include <stdio.h>
#include <string.h> //该函数返回 str 中最后一次出现字符 c 的位置。如果未找到该值,则函数返回一个空指针。
int main() {
const char str[] = "https://github.com/zhangrxiang/learn-c";
const char str2[] = "D:\\WorkSpace\\clionProjects\\learn-c\\string\\strrchr.c";
const char ch = '/';
const char ch2 = '\\';
char *ret; ret = strrchr(str, ch);
// |/| ------ |/learn-c|
printf("|%c| ------ |%s|\n", ch, ret);
printf("%c\n", ret[0]);// /
printf("%ld\n", ret - str + 1);//number 31
printf("%ld\n", ret - str);//index 30 ret = strrchr(str2, ch2);
// |\| ------ |\strrchr.c|
printf("|%c| ------ |%s|\n", ch2, ret);
printf("%c\n", ret[0]); /*** \ */
printf("%c\n", str2[ret - str2]);/*** \ */
printf("%ld\n", ret - str2 + 1);//42
printf("%d\n", (int) strlen(ret));//10
printf("%s\n", ret + 1);//strrchr.c
printf("%c\n", *ret); /*** \ */
printf("%c\n", *(ret + sizeof(char)));//s
printf("%c\n", *(ret + sizeof(char) * 2));//t
printf("%s\n", &(*ret));// \strrchr.c
printf("%s\n", &*(ret + sizeof(char)));//strrchr.c ret = strrchr(str,'A');
if (ret){
printf("exists A\n");
} else{
// no exists A
printf("no exists A\n");
}
return 0;
}

参考文章

转载注明出处

C 标准库 - string.h之strrchr使用的更多相关文章

  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之strpbrk使用

    strpbrk Locate characters in string,Returns a pointer to the first occurrence in str1 of any of the ...

  4. C标准库string.h中几个常用函数的使用详解

    strlen 计算字符串长度 size_t strlen(const char *str) 计算字符串 str 的长度,直到空结束字符,但不包括空结束字符. 函数实现: int Strlen(cons ...

  5. C 标准库 - string.h之memmove使用

    memmove Move block of memory Copies the values of num bytes from the location pointed by source to t ...

  6. C 标准库 - string.h之memcpy使用

    memcpy Copy block of memory Copies the values of num bytes from the location pointed to by source di ...

  7. C 标准库 - string.h之memcmp使用

    memcmp Compare two blocks of memory. Compares the first num bytes of the block of memory pointed by ...

  8. C 标准库 - string.h之memchr使用

    memchr Locate character in block of memory,Searches within the first num bytes of the block of memor ...

  9. C 标准库 - string.h之strlen使用

    strlen Returns the length of the C string str. The length of a C string is determined by the termina ...

随机推荐

  1. 卸载超级兔子后,word打不开(无法创建工作文件),VS2010也没法用(找不到CL.exe)。

    又折腾了一上午,昨天用优化大师和超级兔子整理了电脑,今天来到实验室,vs打开后报错,提示"找不到CL.exe,"(具体提示忘记了,就是找不到CL.exe),打开word2010也是 ...

  2. 使用InstallUtil安装或卸载服务

    使用InstallUtil安装或卸载服务 一.安装服务: C:\Windows\Microsoft.NET\Framework\v4.0.30319\InstallUtil.exe D:\MyServ ...

  3. luogu1357花园(矩阵运算)(状压DP)

    不得不说本蒻做这个题目的时候内心是很蒙蔽的qwq 推了规律找错了结果还没有暴力的分数高qwq...... 开数组\(f[i][j]\)来记录前i个花圃,(这里运用到状压的思想)其中最近的m个的状态(二 ...

  4. 在macbookpro上开启ssh服务

  5. 使用 final 关键字修饰一个变量时,是引用不能变,还是引用的对象不能变?

    使用 final 关键字修饰一个变量时,是指引用变量不能变,引用变量所指向的对象中的内容还是可以改变的.例如,对于如下语句:final StringBuffer a=new StringBuffer( ...

  6. 1. java 的访问修饰符

    一.什么情况下使用修饰符 属性通常使用private封装起来 方法一般使用public用于被调用 会被子类继承的方法,通常使用protected private protected package p ...

  7. ElasticSearch 常用设置

    2.2.0的启动和6.几 启动路径.端口一样,但是进入Head的路径不一样 http://localhost:9200/ 进入Head的方式2.2 的在 http://localhost:9200/_ ...

  8. Oracle 第三方管理工具整理

    Oracle 第三方管理工具整理 1.OB(SI Object Browser) 官方网址: http://www.ctdw.com.cn说明:小软件大功能,个人最爱它的数据库导入.导出功能,一键导入 ...

  9. CDQZ Day2

    模拟题 day2出题人: liu_runda题目名称 一盘大棋 下一代互联网 强连通分量源程序文件名 chess.cpp net.cpp scc.cpp输入文件名 chess.in net.in sc ...

  10. 原来部署好的WCF(可以调用),因为部署.net core,而安装了DotNetCore.2.0.5-WindowsHosting,导致现在WCF站点不可以。

    报错如下: 由于 Web 服务器上的“ISAPI 和 CGI 限制”列表设置,无法提供您请求的页面. 解决方法: 如果出现如下结果,则证明可以啦.