strrchr
Header: <string.h>
- Finds the last occurrence of ch (after conversion to char as if by (char)ch) in the null-terminated byte string pointed to by str (each character interpreted as unsigned char). The terminating null character is considered to be a part of the string and can be found if searching for ‘\0’.
# Declarations
char* strrchr( const char* str, int ch );
/*QChar*/* strrchr( /*QChar*/* str, int ch );
(since C23)
# Parameters
str: pointer to the null-terminated byte string to be analyzedch: character to search for
# Return value
Pointer to the found character in str, or null pointer if no such character is found.
# Example
#include <stdio.h>
#include <string.h>
int main(void)
{
char szSomeFileName[] = "foo/bar/foobar.txt";
char* pLastSlash = strrchr(szSomeFileName, '/');
char* pszBaseName = pLastSlash ? pLastSlash + 1 : szSomeFileName;
printf("Base Name: %s", pszBaseName);
}