Author: Not specified Language: c
Description: Not specified Timestamp: 2013-06-04 17:55:12 +0000
View raw paste Reply

  Using strtok */
#include<stdio.h>
#include<string.h>
intmain( void)
{
  /* initialize array string */
  char string[] = "This is a sentence with 7 tokens";
  char *tokenPtr; /* create char pointer */
printf( "%s\n%s\n\n%s\n",
  "The string to be tokenized is:", string,
  "The tokens are:");
  /* continue tokenizing sentence until tokenPtr becomes NULL */
  while( tokenPtr != NULL) {
printf( "%s\n", tokenPtr );
} /* end while */
  return 0; /* indicates successful termination */
} /* end main */
tokenPtr = strtok( string, " "); /* begin tokenizing sentence */
tokenPtr = strtok( NULL, " "); /* get next token */


The string to be tokenized is:
This is a sentence with 7 tokens
The tokens are:
This
is
a
sentence
with
7
tokens
View raw paste Reply