C Language and Libraries Help (clang.hlp) (
Table of Contents;
Topic list)
Important Notice
The pages on this site contain documentation for very old MS-DOS software,
purely for historical purposes.
If you're looking for up-to-date documentation, particularly for programming,
you should not rely on the information found here, as it will be woefully
out of date.
TOKEN.C
◄Up► ◄Contents► ◄Index► ◄Back►
─────Run-Time Library───────────────────────────────────────────────────────
/* TOKEN.C illustrates tokenizing and searching for any of several
* characters. Functions illustrated include:
* strcspn strspn strpbrk strtok
*/
#include <string.h>
#include <stdio.h>
void main()
{
char string[100], vowels[] = "aeiouAEIOU", seps[] = " \t\n,";
char *p;
int count;
printf( "Enter a string: " );
gets( string );
/* Delete one word at a time. */
p = string;
while( *p )
{
printf( "String remaining: %s\n", p );
p += strcspn( p, seps ); /* Find next separator */
p += strspn( p, seps ); /* Find next nonseparator */
}
/* Count vowels. */
p = string;
count = 0;
do
{
p = strpbrk( p, vowels ); /* Find next vowel */
count++;
} while( *(++p) );
printf( "\nVowels in string: %d\n\n", count - 1 );
/* Break into tokens. */
count = 0;
p = strtok( string, seps ); /* Find first token */
while( p != NULL )
{
printf( "Token %d: %s\n", ++count, p );
p = strtok( NULL, seps ); /* Find next token */
}
}
-♦-