RAD Studio
ContentsIndex
PreviousUpNext
strrchr, _mbsrchr, wcsrchr

Header File 

string.h, mbstring.h 

Category 

Memory and String Manipulation Routines, Inline Routines, C++ Prototyped Routines 

Prototype 

char *strrchr(const char *s, int c); /* C only */ 

const char *strrchr(const char *s, int c); // C++ only 

char *strrchr(char *s, int c); // C++ only 

wchar_t *wcsrchr(const wchar_t *s, wchar_t c); 

unsigned char * _mbsrchr(const unsigned char *s, unsigned int c); 

Description 

Scans a string for the last occurrence of a given character. 

strrchr scans a string in the reverse direction, looking for a specific character. strrchr finds the last occurrence of the character c in the string s. The null-terminator is considered to be part of the string. 

Return Value 

strrchr returns a pointer to the last occurrence of the character c. If c does not occur in s, strrchr returns null. 

Example  

#include <string.h>
#include <stdio.h>
int main(void)
{
   char string[15];
   char *ptr, c = 'r';
   strcpy(string, "This is a string");
   ptr = strrchr(string, c);
   if (ptr)
      printf("The character %c is at position: %d\n", c, ptr-string);
   else
      printf("The character was not found\n");
   return 0;
}

Portability

 
POSIX 
Win32 
ANSI C 
ANSI C++ 
strrchr 
_mbsrchr 
 
 
 
wcsrchr 
 
Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!