Name
wcsrchr
Synopsis
Searches for the rightmost occurrence of a given wide character in a string
#include <wchar.h> wchar_t *wcsrchr
( const wchar_t *s
, wchar_twc
);
The wcsrchr()
function
returns a pointer to the last occurrence of the
wide character value wc
in the string
addressed by s
. If there is no such wide
character in the string, wcsrchr()
returns a null pointer. If
wc
is a null wide character (L'\0'
), then the return value points to
the terminator of the string addressed by
s
.
Example
int main( int argc, char ** argv )
{
wchar_t wmyname[256];
size_t result = mbstowcs( wmyname, argv[0], 256 );
if ( result == -1 )
return -1;
wchar_t *mybasename =wcsrchr
( wmyname, L'/' ); // End of path
if ( mybasename != NULL )
mybasename++;
else
mybasename = wmyname;
wprintf( L"This program was invoked as %ls.\n", mybasename );
}
Get C in a Nutshell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.