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

  1. /* +++Date last modified: 05-Jul-1997 */
  2.  
  3. /*
  4. **  STRDELCH.C - Removes specified character(s) from a string
  5. **
  6. **  public domain demo by Bob Stout
  7. **
  8. **  NOTE: The name of this funtion violates ANSI/ISO 9899:1990 sec. 7.1.3,
  9. **        but this violation seems preferable to either violating sec. 7.13.8
  10. **        or coming up with some hideous mixed-case or underscore infested
  11. **        naming. Also, many SNIPPETS str---() functions duplicate existing
  12. **        functions which are supported by various vendors, so the naming
  13. **        violation may be required for portability.
  14. */
  15.  
  16. #include <stdio.h>
  17. #include <string.h>
  18. #include "snip_str.h"
  19.  
  20. #if defined(__cplusplus) && __cplusplus
  21.  extern "C" {
  22. #endif
  23.  
  24. char *strdelch(char *string, const char *lose)
  25. {
  26.       if (!string || !*string)
  27.             return NULL;
  28.       if (lose)
  29.       {
  30.             char *s;
  31.  
  32.             for (s = string; *s; ++s)
  33.             {
  34.                   if (strchr(lose, *s))
  35.                   {
  36.                         strMove(s, s + 1);
  37.                         --s;
  38.                   }
  39.             }
  40.       }
  41.       return string;
  42. }
  43.  
  44. #if defined(__cplusplus) && __cplusplus
  45.  }
  46. #endif
  47.  
  48. #ifdef TEST
  49.  
  50. main(int argc, char *argv[])
  51. {
  52.       char *strng, *delstrng;
  53.  
  54.       if (3 > argc--)
  55.       {
  56.             puts("Usage: STRDELCH char(s)_to_delete string_1 [...string_N]");
  57.             return -1;
  58.       }
  59.       else  delstrng = *(++argv);
  60.       while (--argc)
  61.       {
  62.             strng = *(++argv);
  63.             printf("strdelch(\"%s\", \"%s\") => ", delstrng, strng);
  64.             printf("\"%s\"\n", strdelch(strng, delstrng));
  65.       }
  66.       return 0;
  67. }
  68.  
  69. #endif /* TEST */
  70.