home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c065 / 1.ddi / CLIB1.ZIP / STRRCHR.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-06-07  |  1.9 KB  |  53 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. /*|                                                              |*/
  11. /*|     Turbo C Run Time Library - Version 3.0                   |*/
  12. /*|                                                              |*/
  13. /*|                                                              |*/
  14. /*|     Copyright (c) 1987,1988,1990 by Borland International    |*/
  15. /*|     All Rights Reserved.                                     |*/
  16. /*|                                                              |*/
  17. /*[]------------------------------------------------------------[]*/
  18.  
  19. #include <string.h>
  20.  
  21. /*---------------------------------------------------------------------*
  22.  
  23. Name            strrchr - scans a string for the last occurrence of a
  24.               given character
  25.  
  26. Usage           char *strrchr(const char *str, int c);
  27.  
  28. Prototype in    string.h
  29.  
  30. Description    strrchr scans a string in the reverse direction, looking for a
  31.         specific character. strrchr finds the last occurrence of the
  32.         character ch in the string str. The null-terminator is considered
  33.         to be part of the string.
  34.  
  35. Return value    strrchr returns a pointer to the last occurrence of the
  36.         character ch. If ch does not occur in str, strrchr returns
  37.         NULL.
  38.  
  39. *---------------------------------------------------------------------*/
  40. #undef strrchr            /* not an intrinsic */
  41. char *_CType strrchr( const char *s, int c )
  42.   {
  43.   register const char *ss;
  44.   register size_t i;
  45.  
  46.   for(i = strlen( s ), ss = s+i; i; i--)
  47.     {
  48.     if( *(--ss) == (char)c )  return( (char *)ss );
  49.     }
  50.  
  51.   return( 0 );
  52.   }
  53.