home *** CD-ROM | disk | FTP | other *** search
/ Aminet 18 / aminetcdnumber181997.iso / Aminet / misc / emu / AROSdev.lha / AROS / compiler / clib / strrchr.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-01-09  |  1.3 KB  |  73 lines

  1. /*
  2.     (C) 1995-96 AROS - The Amiga Replacement OS
  3.     $Id: strrchr.c,v 1.1 1996/12/11 11:18:28 aros Exp $
  4.  
  5.     Desc: ANSI C function strrchr()
  6.     Lang: english
  7. */
  8. #include <stdio.h>
  9.  
  10. /*****************************************************************************
  11.  
  12.     NAME */
  13. #include <string.h>
  14.  
  15.     char * strrchr (
  16.  
  17. /*  SYNOPSIS */
  18.     const char * str,
  19.     int         c)
  20.  
  21. /*  FUNCTION
  22.     Searches for the last character c in a string.
  23.  
  24.     INPUTS
  25.     str - Search this string
  26.     c - Look for this character
  27.  
  28.     RESULT
  29.     A pointer to the first occurence of c in str or NULL if c is not
  30.     found in str.
  31.  
  32.     NOTES
  33.  
  34.     EXAMPLE
  35.     char buffer[64];
  36.  
  37.     strcpy (buffer, "Hello ");
  38.  
  39.     // This returns a pointer to the second l in buffer.
  40.     strrchr (buffer, 'l');
  41.  
  42.     // This returns NULL
  43.     strrchr (buffer, 'x');
  44.  
  45.     BUGS
  46.  
  47.     SEE ALSO
  48.     strrchr()
  49.  
  50.     INTERNALS
  51.     It might seem that the algorithm below is slower than one which
  52.     first finds the end and then walks backwards but that would mean
  53.     to process some characters twice - if the string doesn't contain
  54.     c, it would mean to process every character twice.
  55.  
  56.     HISTORY
  57.     11.12.1996 digulla created
  58.  
  59. ******************************************************************************/
  60. {
  61.     char * p = NULL;
  62.  
  63.     while (*str)
  64.     {
  65.     if (*str == c)
  66.         p = (char *)str;
  67.  
  68.     str ++;
  69.     }
  70.  
  71.     return p;
  72. } /* strrchr */
  73.