2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
#include <stdio.h> #include <string.h> //查找字符串中要查找的字符串最后一次出现的位置 char *strrstr (const char*string, const char*str) { char *index = NULL; char *ret = NULL; int i = 0; do{ index = strstr(string + i++, str); if (index != NULL) ret = index; }while(index != NULL); return ret; } int main() { char str[] = "abc123abc456abc789"; printf("%s\n", strrstr(str, "abc")); return 0; } |
查找字符串中要查找的字符串最后一次出现的位置
C++ Code