home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c082_122 / 1.ddi / CLIBSRC1.ZIP / STRRCHR.C < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-10  |  1.6 KB  |  57 lines

  1. /*-----------------------------------------------------------------------*
  2.  * filename - strrchr.c
  3.  *
  4.  * function(s)
  5.  *        strrchr - scans a string for the last occurrence of a
  6.  *          given character
  7.  *-----------------------------------------------------------------------*/
  8.  
  9. /*
  10.  *      C/C++ Run Time Library - Version 5.0
  11.  *
  12.  *      Copyright (c) 1987, 1992 by Borland International
  13.  *      All Rights Reserved.
  14.  *
  15.  */
  16.  
  17.  
  18. #include <string.h>
  19.  
  20. /*---------------------------------------------------------------------*
  21.  
  22. Name            strrchr - scans a string for the last occurrence of a
  23.                 given character
  24.  
  25. Usage           char *strrchr(const char *str, int c);
  26.  
  27. Prototype in    string.h
  28.  
  29. Description     strrchr scans a string in the reverse direction, looking for a
  30.                 specific character. strrchr finds the last occurrence of the
  31.                 character ch in the string str. The null-terminator is
  32.                 considered to be part of the string.
  33.  
  34. Return value    strrchr returns a pointer to the last occurrence of the
  35.                 character ch. If ch does not occur in str, strrchr returns
  36.                 NULL.
  37.  
  38. *---------------------------------------------------------------------*/
  39. #undef strrchr            /* not an intrinsic */
  40.  
  41. #if defined(__FARFUNCS__)
  42. #include <_farfunc.h>
  43. #endif
  44.  
  45. char * _FARFUNC _CType strrchr( const char _FAR *s, int c )
  46. {
  47.     register const char *ss;
  48.     register size_t i;
  49.  
  50.     for(i = strlen( s ) + 1, ss = s+i; i; i--)
  51.         {
  52.         if( *(--ss) == (char)c )  return( (char *)ss );
  53.         }
  54.  
  55.     return( 0 );
  56. }
  57.