function
<cwchar>
wcsrchr
const wchar_t* wcsrchr (const wchar_t* ws, wchar_t wc);
wchar_t* wcsrchr ( wchar_t* ws, wchar_t wc);
Locate last occurrence of character in wide string
Returns a pointer to the last occurrence of wc in the C wide string ws.
The terminating null wide character is considered part of the string. Therefore, it can also be located to retrieve a pointer to the end of a wide string.
This is the wide character equivalent of strrchr (<cstring>).
Parameters
- ws
- C wide string.
- wc
- Wide character to be located.
Return Value
A pointer to the last occurrence of wc in ws.
If wc is not found, the function returns a null pointer.
Portability
In C, this function is only declared as:
wchar_t * wcsrchr ( const wchar_t *, wchar_t );
instead of the two overloaded versions provided in C++.
Example
1 2 3 4 5 6 7 8 9 10 11
|
/* wcsrchr example */
#include <wchar.h>
int main ()
{
wchar_t wcs[] = L"This is a sample wide string";
wchar_t * pwc;
pwc = wcsrchr (wcs,L's');
wprintf (L"Last occurence of L's' found at %d \n",pwc-wcs+1);
return 0;
}
| |
Output:
Last occurrence of L's' found at 23
|
See also
- strrchr
- Locate last occurrence of character in string (function
)
- wcschr
- Locate first occurrence of character in wide string (function
)
- wmemchr
- Locate character in block of wide characters (function
)
- wcspbrk
- Locate characters in wide string (function
)