曲径通幽论坛

标题: strrchr -- 返回指向指定字符最后一次出现位置指针 [打印本页]

作者: beyes    时间: 2011-6-29 15:44
标题: strrchr -- 返回指向指定字符最后一次出现位置指针
strrchr() 原型为:
[C++] 纯文本查看 复制代码
#include <string.h>
char *strrchr(const char *s, int c);

该函数从字符串 s 中查找 c,在 s 中可能会存在多个 c,但是 strrchr() 返回的是最后一个 c 所在的位置。

测试代码
[C++] 纯文本查看 复制代码
#include <stdio.h>
#include <string.h>

int main(void)
{
        char *p = "strrchr function returns a pointer to the last occurrence of the character c in the string s.";

        char *sp = strrchr (p, 'i');

        printf ("%s\n", sp);

        return 0;
}

运行输出
$ ./strrchr
ing s.





欢迎光临 曲径通幽论坛 (http://www.groad.net/bbs/) Powered by Discuz! X3.2