home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / snip9707.zip / STRRPBRK.C < prev    next >
C/C++ Source or Header  |  1997-07-05  |  1KB  |  53 lines

  1. /* +++Date last modified: 05-Jul-1997 */
  2.  
  3. /*
  4. ** strrpbrk() - reverse of strpbrk() - Finds the last occurrence of
  5. **              any characters from szChars found in szString.
  6. **
  7. ** Donated to SNIPPETS by Phi Nguyen 1995, modified by Bob Stout
  8. */
  9.  
  10. #include <stdio.h>
  11. #include <string.h>
  12. #include "snip_str.h"
  13.  
  14. #if defined(__cplusplus) && __cplusplus
  15.  extern "C" {
  16. #endif
  17.  
  18. char *strrpbrk(const char *szString, const char *szChars)
  19. {
  20.       const char  *p;
  21.       char        *p0, *p1;
  22.  
  23.       for (p = szChars, p0 = p1 = NULL; p && *p; ++p)
  24.       {
  25.             p1 = strrchr(szString, *p);
  26.             if (p1 && p1 > p0)
  27.                   p0 = p1;
  28.       }
  29.       return p0;
  30. }
  31.  
  32. #if defined(__cplusplus) && __cplusplus
  33.  }
  34. #endif
  35.  
  36. #ifdef TEST
  37.  
  38. main()
  39. {
  40.       char  string[] = "This is a testing string",
  41.             chars[]  = "xyzet",
  42.            *ptr;
  43.  
  44.       ptr = strrpbrk(string, chars);
  45.  
  46.       if (ptr)
  47.             printf("One or more of \"%s\" found at \"%s\"\n", chars, ptr);
  48.       else  printf("Can't find any of \"%s\" in \"%s\".\n", chars, string);
  49.       return 0;
  50. }
  51.  
  52. #endif /* TEST */
  53.