- strrchr
定义及用法:
strrchr函数的作用是:查找一个字符在某个字符串中末次出现的位置,并返回从字符串中的这个位置起,一直到字符串结束的所有字符。如果未能找到指定字符,那么函数将返回NULL。
例子
#include <string.h>
#include <stdio.h>
int main(void)
{
char string[20];
char *ptr, c = 'r';
strcpy(string, "There are two rings");
ptr = strrchr(string, c);
if (ptr)
printf("The character %c is at position: %s\n", c, ptr);
else
printf("The character was not found\n");
return 0;
}
strrchr返回的指针应当指向"rings"里的'r',而不是“There”或"are"里的'r'。
运行结果是:The character r is at position:rings
本文详细介绍了C语言中的strrchr函数,包括其作用、使用方法和一个实例演示如何查找字符串中末次出现的特定字符。

被折叠的 条评论
为什么被折叠?



