原型:char *strrchr(const char *str, char c);
#include<string.h>
找一个字符c在另一个字符串str中末次出现的位置(也就是从str的右侧开始查找字符c首次出现的位置),并返回从字符串中的这个位置起,一直到字符串结束的所有字符。如果未能找到指定字符,那么函数将返回NULL。
The strrchr function finds the last occurrence of c (converted to char) in str. The search includes the terminating null character.
应用举例:(来自BACnet协议filename.c)
char *filename_remove_path( const char *filename_in)
{
char *filename_out = (char *) filename_in;
/* allow the device ID to be set */
if (filename_in) {
filename_out = strrchr(filename_in, '\\');
if (!filename_out) {
filename_out = strrchr(filename_in, '/');
}
/* go beyond the slash */
if (filename_out) {
filename_out++;
} else {
/* no slash in filename */
filename_out = (char *) filename_in;
}
}
return filename_out;
}