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

char *gntoken(ntoken,line,delimiters,token)
/*============================================================================*/
/* PURPOSE: RETURN THE SPECIFIED TOKEN (0..N) FROM THE LINE.  LINE MUST HAVE
/*	AT LEAST NTOKEN TOKENS IN IT, OR NULL WILL BE RETURNED.
/* INPUTS:
/*	NTOKEN		WHICH TOKEN (0..N) IS DESIRED FROM LINE.
/*	LINE		LINE CONTAINING TOKENS.
/*	DELIMITERS	LIST OF POSSIBLE TOKEN DELIMITERS.
/* OUTPUTS:
/*	TOKEN		NTOKEN-TH TOKEN FROM LINE.
/*	RETURN VALUE	POINTER TO TOKEN.
/* WRITTEN: M.V.GRIESHABER
/* LAST MODIFICATION: 11 JUNE 1991 MVG
*/
   int ntoken;		/* WHICH TOKEN IS DESIRED (0..N). */
   char *line;		/* LINE CONTAINING TOKENS. */
   char *delimiters;	/* POSSIBLE TOKEN DELIMITERS TO USE. */
   char *token;		/* RETURNED COPY OF TOKEN. */
   {
   char *working_line;	/* WORKING COPY OF LINE. */
   int ntokens;		/* WHICH TOKEN IS BEING PROCESSED. */
   char *strtok_ptr;	/* POINTER FOR STRTOK. */

   strtok_ptr= working_line= strdup(line);

   ntokens=0;
   while (strcpy(token,strtok(strtok_ptr,delimiters))!=NULL)
      {
      if (ntoken==ntokens)
         {
         /* THIS IS THE REQUESTED TOKEN. */
         free(working_line);
         return(token);
         }
      strtok_ptr=NULL;
      ntokens++;
      }

   /* NO SUCH TOKEN (ILLEGAL TOKEN NUMBER REQUESTED). */
   strcpy(token,"");
   free(working_line);
   return(NULL);
   }
Modified: Fri Feb 11 17:00:00 1994 GMT
Page accessed 4823 times since Sat Apr 17 21:58:56 1999 GMT