CCL Home Page
Up Directory CCL count_tokens
#include "utility.h"

int count_tokens(line,delimiters)
/*============================================================================*/
/* PURPOSE: RETURN A COUNT OF THE NUMBER OF TOKENS ON THE LINE.
/* INPUTS:
/*	LINE		LINE CONTAINING TOKENS.
/*	DELIMITERS	LIST OF POSSIBLE DELIMITERS BETWEEN TOKENS.
/* OUTPUTS:
/*	RETURN VALUE	NUMBER OF TOKENS IN LINE.
/* WRITTEN: M.V.GRIESHABER
/* LAST MODIFICATION: 11 JUNE 1991 MVG
*/
   char *line;		/* LINE CONTAINING TOKENS. */
   char *delimiters;	/* POSSIBLE TOKEN DELIMITERS TO USE. */
   {
   char *working_line;	/* WORKING COPY OF LINE. */
   int ntokens;		/* NUMBER OF TOKENS FOUND IN LINE. */
   char *strtok_ptr;	/* POINTER FOR STRTOK. */

   strtok_ptr= working_line= strdup(line);

   ntokens=0;
   while (strtok(strtok_ptr,delimiters)!=NULL)
      {
      ntokens++;
      strtok_ptr=NULL;
      }

   free(working_line);
   return(ntokens);
   }
Modified: Fri Feb 11 17:00:00 1994 GMT
Page accessed 5050 times since Sat Apr 17 21:58:52 1999 GMT