home *** CD-ROM | disk | FTP | other *** search
/ Piper's Pit BBS/FTP: ibm 0020 - 0029 / ibm0020-0029 / ibm0028.tar / ibm0028 / GRLF-C-2.ZIP / GFUNC / STRWC.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-05-30  |  889 b   |  45 lines

  1. /*
  2.  * strwc.c
  3.  * contains: strwc()
  4.  *
  5.  */
  6.  
  7. #include <stdio.h>
  8. #include "gfuncts.h"
  9.  
  10. /*
  11.  *  int
  12.  * strwc(str)
  13.  *
  14.  * ARGUMENT
  15.  *  (char *)    str    -    points to string to count
  16.  *
  17.  * DESCRIPTION
  18.  *  string word count,  the string is scanned from left to right and words
  19.  *  are counted.  The number of words is returned.  The function counts any
  20.  *  number of 1 or more contigious characters bounded by white space or
  21.  *  the beginning or end of the string as a word.
  22.  *
  23.  * RETURNS
  24.  *   number of words counted
  25.  *
  26.  * AUTHOR
  27.  *   Copyright (C)1987-1990 Greenleaf Software Inc. All Rights Reserved.
  28.  *
  29.  * MODIFICATIONS
  30.  *
  31.  */
  32. int GF_CONV strwc(str)
  33. char *str;
  34. {
  35.     int wordcount,inword;
  36.  
  37.     for(wordcount=inword=0;*str;++str)
  38.         if(!gisspace(*str)&&!inword) {
  39.             ++wordcount;
  40.             inword=1;
  41.         } else if(gisspace(*str)&&inword)
  42.             inword=0;
  43.     return(wordcount);
  44. }
  45.