曲径通幽论坛

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

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

index() 用来找出参数 s 字符串中第一个出现的字符 c ,找到后就将该字符出现的地址返回。字符串的结束符 NULL 也会被视为字符串的一部分。

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

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

        char *p;

        p = index(s, '8');

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

        return 0;
}

运行输出:
./index
85314586238521783658





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