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

  1. /* +++Date last modified: 05-Jul-1997 */
  2.  
  3. /*
  4. **  Originally published as part of the MicroFirm Function Library
  5. **
  6. **  Copyright 1987-88, Robert B.Stout
  7. **
  8. **  The user is granted a free limited license to use this source file
  9. **  to create royalty-free programs, subject to the terms of the
  10. **  license restrictions specified in the LICENSE.MFL file.
  11. **
  12. **  Makes all whitespace single spaces. Passed a string, lv1ws()
  13. **  converts all multiple whitespace characters to single spaces.
  14. */
  15.  
  16. #include <ctype.h>
  17. #include "snip_str.h"
  18.  
  19. #if defined(__cplusplus) && __cplusplus
  20.  extern "C" {
  21. #endif
  22.  
  23. void lv1ws(char *str)
  24. {
  25.       char *ibuf, *obuf;
  26.       int i, cnt;
  27.  
  28.       if (str)
  29.       {
  30.             ibuf = obuf = str;
  31.             i = cnt = 0;
  32.  
  33.             while(*ibuf)
  34.             {
  35.                   if(isspace(*ibuf) && cnt)
  36.                         ibuf++;
  37.                   else
  38.                   {
  39.                         if (!isspace(*ibuf))
  40.                               cnt = 0;
  41.                         else
  42.                         {
  43.                               *ibuf = ' ';
  44.                               cnt = 1;
  45.                         }
  46.                         obuf[i++] = *ibuf++;
  47.                   }
  48.             }
  49.             obuf[i] = '\0';
  50.       }
  51. }
  52.  
  53. #if defined(__cplusplus) && __cplusplus
  54.  }
  55. #endif
  56.