home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_09_08 / 9n08101a < prev    next >
Text File  |  1991-06-05  |  827b  |  29 lines

  1. char *word_breaks = " \n\t";  
  2. int slow_wordcount(char *str)
  3.    {       
  4.    int count = 0;  
  5.    char *s;       
  6.    s=str;       
  7.    s+=strspn(s,word_breaks);  //Skip leading white space       
  8.    while(s)
  9.        {
  10.        s=strpbrk(s,word_breaks);   //Find the beginning of the white space  
  11.        if(s) s+=strspn(s,word_breaks);  //Find the end of the white space  
  12.        count++;  //Increment count - Note it starts as 0 not 1       
  13.        }
  14.    return(count);  
  15.    }
  16.  
  17. void slow_str_to_ptrarray(char *orgstr, char *ptrarray[])
  18.    {
  19.    int i=0;       
  20.    char *s;       
  21.    s=strtok(orgstr,word_breaks); //Find the first word       
  22.    while(*s)
  23.        {
  24.        ptrarray[i]=s;      //assign it  
  25.        i++;  
  26.        s=strtok(NULL,word_breaks);   //Find the rest of the words       
  27.        }
  28.    }
  29.