曲径通幽论坛

标题: rindex() -- 找出字符串中最后一个出现的指定字符 [打印本页]

作者: beyes    时间: 2011-12-21 16:32
标题: rindex() -- 找出字符串中最后一个出现的指定字符
rindex() 原型如下:
[C++] 纯文本查看 复制代码
#include <strings.h>
char *rindex(const char *s, int c);

rindex() 用来找出参数 s 所指的字符串中最后一个出现的由参数 c 所指定的字符,然后将该字符所在的位置(地址)返回,字符串的结束符(NULL)也视为字符串的一部分。

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

int main()
{
        char *s = "183028198114850329282223333";

        char *p = rindex(s, '8');

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

        return 0;
}

运行输出:
./rindex
82223333





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